Skip to contentSkip to conversation

usertools/hugepages: show usage if no action specified

PATCH Superseded Thomas Monjalon 3 participants 6 messages Nov 4, 2022 – Nov 22, 2022

lore
Share & tools
lore
#0 lore raw

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
index a22d504d3a..823cfcf185 100755
@@ -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
#1 lore raw

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.

---
 usertools/dpdk-hugepages.py | 4 ++++
 1 file changed, 4 insertions(+)
usertools/dpdk-hugepages.py +0 -0
index a22d504d3a..823cfcf185 100755

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
#2 lore raw

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.

---
 usertools/dpdk-hugepages.py | 4 ++++
 1 file changed, 4 insertions(+)
usertools/dpdk-hugepages.py +0 -0
index a22d504d3a..823cfcf185 100755

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:

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")

#3 lore raw

PATCH v2 1/1 usertools/hugepages: show usage if no action specified

In reply to 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.

---
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
index a22d504d3a..bf2575ba36 100755
@@ -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
Acked-by on v2 1/1
#4 lore raw
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.

Signature · 1 line
David Marchand
author Applied
#5 lore raw

22/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

Applied