DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] usertools/hugepages: show usage if no action specified
@ 2022-11-04 11:30 Thomas Monjalon
  2022-11-07  9:39 ` Robin Jarry
  2022-11-22 15:32 ` [PATCH v2] " Thomas Monjalon
  0 siblings, 2 replies; 6+ messages in thread
From: Thomas Monjalon @ 2022-11-04 11:30 UTC (permalink / raw)
  To: dev; +Cc: rjarry, bruce.richardson, stephen, dmitry.kozliuk

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 <thomas@monjalon.net>
---
 usertools/dpdk-hugepages.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index a22d504d3a..823cfcf185 100755
--- a/usertools/dpdk-hugepages.py
+++ b/usertools/dpdk-hugepages.py
@@ -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:
-- 
2.36.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usertools/hugepages: show usage if no action specified
  2022-11-04 11:30 [PATCH] usertools/hugepages: show usage if no action specified Thomas Monjalon
@ 2022-11-07  9:39 ` Robin Jarry
  2022-11-22 15:22   ` Thomas Monjalon
  2022-11-22 15:32 ` [PATCH v2] " Thomas Monjalon
  1 sibling, 1 reply; 6+ messages in thread
From: Robin Jarry @ 2022-11-07  9:39 UTC (permalink / raw)
  To: Thomas Monjalon, dev; +Cc: bruce.richardson, stephen, dmitry.kozliuk

Thomas Monjalon, Nov 04, 2022 at 12:30:
> 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 <thomas@monjalon.net>
> ---
>  usertools/dpdk-hugepages.py | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
> index a22d504d3a..823cfcf185 100755
> --- a/usertools/dpdk-hugepages.py
> +++ b/usertools/dpdk-hugepages.py
> @@ -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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] usertools/hugepages: show usage if no action specified
  2022-11-07  9:39 ` Robin Jarry
@ 2022-11-22 15:22   ` Thomas Monjalon
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2022-11-22 15:22 UTC (permalink / raw)
  To: Robin Jarry; +Cc: dev, bruce.richardson, stephen, dmitry.kozliuk

07/11/2022 10:39, Robin Jarry:
> Thomas Monjalon, Nov 04, 2022 at 12:30:
> > 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 <thomas@monjalon.net>
> > ---
> >  usertools/dpdk-hugepages.py | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
> > index a22d504d3a..823cfcf185 100755
> > --- a/usertools/dpdk-hugepages.py
> > +++ b/usertools/dpdk-hugepages.py
> > @@ -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

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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] usertools/hugepages: show usage if no action specified
  2022-11-04 11:30 [PATCH] usertools/hugepages: show usage if no action specified Thomas Monjalon
  2022-11-07  9:39 ` Robin Jarry
@ 2022-11-22 15:32 ` Thomas Monjalon
  2022-11-22 15:38   ` David Marchand
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas Monjalon @ 2022-11-22 15:32 UTC (permalink / raw)
  To: dev; +Cc: rjarry, bruce.richardson, stephen, dmitry.kozliuk

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 <thomas@monjalon.net>
---
v2: replace parser.print_usage() and sys.exit(1) with parser.error()
---
 usertools/dpdk-hugepages.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/usertools/dpdk-hugepages.py b/usertools/dpdk-hugepages.py
index a22d504d3a..bf2575ba36 100755
--- a/usertools/dpdk-hugepages.py
+++ b/usertools/dpdk-hugepages.py
@@ -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:
-- 
2.36.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] usertools/hugepages: show usage if no action specified
  2022-11-22 15:32 ` [PATCH v2] " Thomas Monjalon
@ 2022-11-22 15:38   ` David Marchand
  2022-11-22 15:42     ` Thomas Monjalon
  0 siblings, 1 reply; 6+ messages in thread
From: David Marchand @ 2022-11-22 15:38 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, rjarry, bruce.richardson, stephen, dmitry.kozliuk

On Tue, Nov 22, 2022 at 4:33 PM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 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 <thomas@monjalon.net>

Acked-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] usertools/hugepages: show usage if no action specified
  2022-11-22 15:38   ` David Marchand
@ 2022-11-22 15:42     ` Thomas Monjalon
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2022-11-22 15:42 UTC (permalink / raw)
  To: dev; +Cc: rjarry, bruce.richardson, stephen, dmitry.kozliuk, David Marchand

22/11/2022 16:38, David Marchand:
> On Tue, Nov 22, 2022 at 4:33 PM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > 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 <thomas@monjalon.net>
> 
> Acked-by: David Marchand <david.marchand@redhat.com>

Applied




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-22 15:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 11:30 [PATCH] usertools/hugepages: show usage if no action specified Thomas Monjalon
2022-11-07  9:39 ` Robin Jarry
2022-11-22 15:22   ` Thomas Monjalon
2022-11-22 15:32 ` [PATCH v2] " Thomas Monjalon
2022-11-22 15:38   ` David Marchand
2022-11-22 15:42     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).