[cmaster-next] [PATCH] tools: teach xml2cli.pl the "{}" notation for optional arguments

Renato Westphal renato at opensourcerouting.org
Mon Dec 19 15:35:39 EST 2016


Requested by Daniel Walton.

Signed-off-by: Renato Westphal <renato at opensourcerouting.org>
---
 tools/xml2cli.pl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/xml2cli.pl b/tools/xml2cli.pl
index 1b45e7f..b84ab67 100755
--- a/tools/xml2cli.pl
+++ b/tools/xml2cli.pl
@@ -196,7 +196,11 @@ sub generate_code {
 			$helpstr .= $::options{$options_name}{'help'};
 		} else {
 			$funcname .= $node{'name'} . " ";
-			$cmdstr .= $node{'name'} . " ";
+			if ($node{'optional'}) {
+				$cmdstr .= "{" . $node{'name'} . "} ";
+			} else {
+				$cmdstr .= $node{'name'} . " ";
+			}
 			$helpstr .= "\n       \"" . $node{'help'} . "\\n\"";
 		}
 
@@ -279,6 +283,7 @@ sub parse_tree {
 	$node{'help'} = $xml_node->findvalue('./@help');
 	$node{'function'} = $xml_node->findvalue('./@function');
 	$node{'ifdef'} = $xml_node->findvalue('./@ifdef');
+	$node{'optional'} = $xml_node->findvalue('./@optional');
 
 	# push node to stack
 	push (@nodes, \%node);
-- 
1.9.1





More information about the dev mailing list