Switch from optparse to argparse
authorBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 05:37:05 +0000 (00:37 -0500)
committerBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 05:37:05 +0000 (00:37 -0500)
scripts/invirt-getconf

index d56b06f..5b3681b 100755 (executable)
@@ -16,22 +16,6 @@ Examples:
   invirt-getconf hosts.0.ip
 """
 
-def main(argv):
-    try:
-        parser = OptionParser(usage = '%prog [options] key',
-                description = __doc__.strip().split('\n\n')[0])
-        parser.add_option('-r', '--refresh',
-                action = 'store_true',
-                help = 'force the cache to be regenerated')
-        parser.add_option('-l', '--ls',
-                action = 'store_true',
-                help = 'list node\'s children')
-        opts, args = parser.parse_args()
-
-        if len(args) > 1:
-            raise invirt_exception(__doc__.strip())
-        elif args and args[0]:
-            components = args[0].split('.')
 import argparse
 import sys
 import yaml
@@ -42,6 +26,17 @@ import invirt
 class InvirtException(Exception):
     pass
 
+
+def main():
+    parser = argparse.ArgumentParser(description='Get values from invirt configuration file')
+    parser.add_argument('-r', '--refresh', action='store_true', help='Force regenerate the cache')
+    parser.add_argument('-l', '--ls', action='store_true', help='List children of node')
+    parser.add_argument('path', nargs='?', default='', help='Path of value to get')
+
+    args = parser.parse_args()
+
+    components = args.path.split('.')
+
         else:
             components = []