usertools/hugepages: show usage if no action specified
PATCH 1/1 usertools/hugepages: show usage if no action specified
Previously, the script was doing nothing if no argument was provided.
If neither show, mount/unmount, clear/reserve are specified, it is assumed that the user does not know how to use the script. So the usage is printed and an error code is used in exit. The user will understand something is wrong,
and can recall the script with the option -h to get more information.
--- usertools/dpdk-hugepages.py | 4 ++++ 1 file changed, 4 insertions(+)
usertools/dpdk-hugepages.py +4 -0
@@ -272,6 +272,10 @@ def main(): args.reserve = args.setup args.mount = True + if not (args.show or args.mount or args.unmount or args.clear or args.reserve): + parser.print_usage() + sys.exit(1) + if args.pagesize: pagesize_kb = get_memsize(args.pagesize) else:
Signature · 1 line
2.36.1
Thomas Monjalon, Nov 04, 2022 at 12:30:
Quoted 18 lines
Previously, the script was doing nothing if no argument was provided.
If neither show, mount/unmount, clear/reserve are specified, it is assumed that the user does not know how to use the script. So the usage is printed and an error code is used in exit. The user will understand something is wrong,
and can recall the script with the option -h to get more information.Signed-off-by Thomas Monjalon <[email protected]>--- usertools/dpdk-hugepages.py | 4 ++++ 1 file changed, 4 insertions(+)usertools/dpdk-hugepages.py +0
-0
usertools/dpdk-hugepages.py def main(): · line 277
Quoted 6 lines
usertools/dpdk-hugepages.py +3
-0@@ -272,6 +272,10 @@ def main(): args.reserve = args.setup args.mount = True + if not (args.show or args.mount or args.unmount or args.clear or args.reserve): + parser.print_usage() + sys.exit(1)
Hi Thomas,
I believe you can do:
parser.error("at least one of -s/-c/-m/-u/-r/--setup is required")and omit sys.exit(1).
$ ~/dev/dpdk/usertools/dpdk-hugepages.py usage: dpdk-hugepages.py [-h] [--show] [--clear] [--mount] [--unmount] [--node NODE] [--pagesize SIZE] [--reserve SIZE] [--setup SIZE] dpdk-hugepages.py: error: at least one of -s/-c/-m/-u/-r/--setup is required
07/11/2022 10:39, Robin Jarry:
Quoted 30 lines
Thomas Monjalon, Nov 04, 2022 at 12:30:
Quoted 18 lines
Previously, the script was doing nothing if no argument was provided.
If neither show, mount/unmount, clear/reserve are specified, it is assumed that the user does not know how to use the script. So the usage is printed and an error code is used in exit. The user will understand something is wrong,
and can recall the script with the option -h to get more information.Signed-off-by Thomas Monjalon <[email protected]>--- usertools/dpdk-hugepages.py | 4 ++++ 1 file changed, 4 insertions(+)usertools/dpdk-hugepages.py +0
-0usertools/dpdk-hugepages.py def main(): · line 277
Quoted 6 lines
usertools/dpdk-hugepages.py +3
-0@@ -272,6 +272,10 @@ def main(): args.reserve = args.setup args.mount = True + if not (args.show or args.mount or args.unmount or args.clear or args.reserve): + parser.print_usage() + sys.exit(1)Hi Thomas,
I believe you can do:
Quoted 7 lines
parser.error("at least one of -s/-c/-m/-u/-r/--setup is required")and omit
sys.exit(1).$ ~/dev/dpdk/usertools/dpdk-hugepages.py usage: dpdk-hugepages.py [-h] [--show] [--clear] [--mount] [--unmount] [--node NODE] [--pagesize SIZE] [--reserve SIZE] [--setup SIZE] dpdk-hugepages.py: error: at least one of -s/-c/-m/-u/-r/--setup is required
It is a long message and not long enough to be accurate (long options are missing). I would go with parser.error("no action specified")
PATCH v2 1/1 usertools/hugepages: show usage if no action specified
In reply to Thomas MonjalonPreviously, the script was doing nothing if no argument was provided.
If neither show, mount/unmount, clear/reserve are specified, it is assumed that the user does not know how to use the script. So the usage and an error message are printed.
The exit code will be non-zero.
The user will understand something is wrong,
and can recall the script with the option -h to get more information.
---
v2: replace parser.print_usage() and sys.exit(1) with parser.error()
--- usertools/dpdk-hugepages.py | 3 +++ 1 file changed, 3 insertions(+)
usertools/dpdk-hugepages.py +3 -0
@@ -272,6 +272,9 @@ def main(): args.reserve = args.setup args.mount = True + if not (args.show or args.mount or args.unmount or args.clear or args.reserve): + parser.error("no action specified") + if args.pagesize: pagesize_kb = get_memsize(args.pagesize) else:
Signature · 1 line
2.36.1
Quoted 11 lines · Thomas Monjalon
Previously, the script was doing nothing if no argument was provided.
If neither show, mount/unmount, clear/reserve are specified, it is assumed that the user does not know how to use the script. So the usage and an error message are printed.
The exit code will be non-zero.
The user will understand something is wrong,
and can recall the script with the option -h to get more information.Signed-off-by Thomas Monjalon <[email protected]>
Signature · 1 line
David Marchand
Thomas Monjalon
Applied22/11/2022 16:38, David Marchand:
Quoted 11 lines · Thomas Monjalon
Quoted 10 lines
Previously, the script was doing nothing if no argument was provided.
If neither show, mount/unmount, clear/reserve are specified, it is assumed that the user does not know how to use the script. So the usage and an error message are printed.
The exit code will be non-zero.
The user will understand something is wrong,
and can recall the script with the option -h to get more information.
Quoted 3 lines
Quoted 1 line
Signed-off-by Thomas Monjalon <[email protected]>Acked-by David Marchand <[email protected]>
Applied