Skip to contentSkip to conversation

yocto-check-layer: make argument parsing unambiguous

PATCH In review Ross Burton 2 participants 3 messages Dec 10, 2020 – Dec 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 yocto-check-layer: make argument parsing unambiguous

Currently the argument parser uses nargs=+ for both the layers (positional arguments) and machines/dependencies/addition layers (optional arguments). This means it's impossible to determine what is meant by:

$ yocto-check-layer --machines a b c

Is this machines=(a,b) and layers=(c), or machines=(a) and layers=(b,c)? Or even machines=(a,b,c) and layers=(), which results in a parse failure as the layers are mandatory?

The workaround is to re-order the arguments to an unambiguous form:

$ yocto-check-layer b c --machines a

However this means the user needs to know the problem and how to work around it. Instead, change the parser to require an explicit --layers argument:

$ yocto-check-layer --machines a --layers b c

Also improve the other arguments by adding clearer metavars and short options.

[ YOCTO #14148 ]

---
 scripts/yocto-check-layer | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
scripts/yocto-check-layer +5 -5
index b7c83c8b54..7c7d6013d8 100755
@@ -45,15 +45,15 @@ def main():
     parser = argparse.ArgumentParser(
             description="Yocto Project layer checking tool",
             add_help=False)
-    parser.add_argument('layers', metavar='LAYER_DIR', nargs='+',
-            help='Layer to check')
+    parser.add_argument('-l', '--layers', metavar='LAYER_DIR', nargs='+',
+            required=True, help='Layers to check')
     parser.add_argument('-o', '--output-log',
             help='File to output log (optional)', action='store')
-    parser.add_argument('--dependency', nargs="+",
+    parser.add_argument('-p', '--dependency', nargs="+", metavar='LAYER_DIR',
             help='Layers to process for dependencies', action='store')
-    parser.add_argument('--machines', nargs="+",
+    parser.add_argument('-m', '--machines', nargs="+", metavar='MACHINE',
             help='List of MACHINEs to be used during testing', action='store')
-    parser.add_argument('--additional-layers', nargs="+",
+    parser.add_argument('-a', '--additional-layers', nargs="+", metavar='LAYER_DIR',
             help='List of additional layers to add during testing', action='store')
     group = parser.add_mutually_exclusive_group()
     group.add_argument('--with-software-layer-signature-check', action='store_true', dest='test_software_layer_signatures',
Signature · 1 line
2.25.1
#1 lore raw
Quoted 24 lines · Ross Burton

Currently the argument parser uses nargs=+ for both the layers (positional arguments) and machines/dependencies/addition layers (optional arguments). This means it's impossible to determine what is meant by:

$ yocto-check-layer --machines a b c

Is this machines=(a,b) and layers=(c), or machines=(a) and layers=(b,c)? Or even machines=(a,b,c) and layers=(), which results in a parse failure as the layers are mandatory?

The workaround is to re-order the arguments to an unambiguous form:

$ yocto-check-layer b c --machines a

However this means the user needs to know the problem and how to work around it. Instead, change the parser to require an explicit --layers argument:

$ yocto-check-layer --machines a --layers b c

Also improve the other arguments by adding clearer metavars and short options.

Quoted 6 lines

[ YOCTO #14148 ]

---
 scripts/yocto-check-layer | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

https://autobuilder.yoctoproject.org/typhoon/#/builders/39/builds/2825

Do we need to update the way we're calling it on the autobuilder?

Cheers,

Richard