From 8becf9cf697252d70b65550ec45f9cc347c80c3d Mon Sep 17 00:00:00 2001
From: Rob Austein <sra@hactrn.net>
Date: Mon, 6 Aug 2007 15:22:28 +0000
Subject: Checkpoint

svn path=/scripts/irbe-cli.py; revision=825
---
 scripts/irbe-cli.py | 59 +++++++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 24 deletions(-)

(limited to 'scripts/irbe-cli.py')

diff --git a/scripts/irbe-cli.py b/scripts/irbe-cli.py
index 5a29774a..b2be9e16 100755
--- a/scripts/irbe-cli.py
+++ b/scripts/irbe-cli.py
@@ -11,37 +11,48 @@ rng = lxml.etree.RelaxNG(lxml.etree.parse("left-right-schema.rng"))
 class command(object):
   options = ()
 
-  def __init__(self, argv):
-    opts, args = getopt.getopt(argv[2:], "", [x[2:] for x in self.options])
-    for o, a in opts:
-      getattr(self, o[2:])(a)
+  def getopt(self, argv):
+    if options:
+      opts, args = getopt.getopt(argv, "", [x[2:] for x in self.options])
+      for o, a in opts:
+        getattr(self, o[2:])(a)
+      return args
+    else:
+      return argv
+
+  def self_id(self, arg):
+    self.self_id = arg
+
+
 
 class help(command):
-  options = ('--tweedledee', '--tweedledum')
+  def run(self, msg):
+    print "Usage:", sys.argv[0]
+    for k,v in dispatch.iteritems():
+      print " ".join((k,) + v.options)
+
+class self(command):
+  options = ("--action", "--self_id", "--extension")
 
-  def tweedledee(self, arg): print "tweedledee"
+  def __init__(self):
+    self.extensions = {}
 
-  def tweedledum(self, arg): print "tweedledum"
+  def extension(self, arg):
+    kv = arg.split(":", 1)
+    self.extensions[k] = v
 
-  def __call__(self):
-    print "Boy this sure is an interesting help command, huh?"
+  def run(self, msg):
+    pdu = rpki.left_right.self_elt()
+    
 
-class wombat(command):
-  def __call__(self):
-    print "I am the wombat!"
 
-top_dispatch = dict((x.__name__, x) for x in (help, wombat))
+dispatch = dict((x.__name__, x) for x in (help, self))
 
-cmd = top_dispatch[sys.argv[1]](sys.argv)
-cmd()
+msg = rpki.left_right.msg()
 
-if False:
+argv = sys.argv[1:]
+while argv:
+  cmd = dispatch[argv[0]]
+  argv = getopt(argv[1:])
+  cmd.run(msg)
 
-  dispatch = { "--help"   : help, "--usage"  : usage, "--wombat" : wombat }
-  try:
-    opts, args = getopt.getopt(sys.argv[1:], "", [x[2:] for x in dispatch.keys()])
-  except getopt.GetoptError:
-    print "You're confused, aren't you?"
-    sys.exit(1)
-  for o, a in opts:
-    dispatch[o]()
-- 
cgit v1.2.3