summaryrefslogtreecommitdiff
path: root/scripts/build-command-templates
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2017-09-14 04:58:17 +0200
committerDaniil Baturin <daniil@baturin.org>2017-09-14 04:58:17 +0200
commit9181e13af0d7400f20636525cf5879c2036c4119 (patch)
treef2105beefbcdec84696a63e069db6f1a0eed58fe /scripts/build-command-templates
parent4d1e6f378a9e99c6168e872ab8e795382514851e (diff)
downloadvyos-1x-9181e13af0d7400f20636525cf5879c2036c4119.tar.gz
vyos-1x-9181e13af0d7400f20636525cf5879c2036c4119.zip
T388: nicer options handling and output.
Diffstat (limited to 'scripts/build-command-templates')
-rwxr-xr-xscripts/build-command-templates33
1 files changed, 12 insertions, 21 deletions
diff --git a/scripts/build-command-templates b/scripts/build-command-templates
index 6801defbb..6cfaa2bc1 100755
--- a/scripts/build-command-templates
+++ b/scripts/build-command-templates
@@ -22,36 +22,27 @@
import sys
import os
-import getopt
+import argparse
import copy
import functools
-import pprint
-
from lxml import etree as ET
## Get arguments
-if len(sys.argv) < 4:
- print("Usage: {0} <interface definition file> <schema file> <output directory>".format(sys.argv[0]))
- sys.exit(1)
-
-input_file = sys.argv[1]
-schema_file = sys.argv[2]
-output_dir = sys.argv[3]
+parser = argparse.ArgumentParser(description='Converts new-style XML interface definitions to old-style command templates')
+parser.add_argument('--debug', help='Enable debug information output', action='store_true')
+parser.add_argument('INPUT_FILE', type=str, help="XML interface definition file")
+parser.add_argument('SCHEMA_FILE', type=str, help="RelaxNG schema file")
+parser.add_argument('OUTPUT_DIR', type=str, help="Output directory")
+args = parser.parse_args()
-debug = False
-try:
- opts, args = getopt.getopt(sys.argv[4:], '', ['debug=', ])
- for opt, arg in opts:
- if opt == '--debug':
- if arg == "1":
- debug = True
-except getopt.GetoptError as err:
- pass
-
+input_file = args.INPUT_FILE
+schema_file = args.SCHEMA_FILE
+output_dir = args.OUTPUT_DIR
+debug = args.debug
## Load and validate the inputs
@@ -176,7 +167,7 @@ def make_node_def(props):
node_def += "end: sudo sh -c \"{0}\"\n".format(props["owner"])
if debug:
- print("The content of node_def:", node_def)
+ print("The contents of the node.def file:\n", node_def)
return node_def