diff mbox

[iproute2,1/2] devlink: write usage help messages to stderr

Message ID 1469205270-6180-1-git-send-email-jiri@resnulli.us
State Accepted, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Jiri Pirko July 22, 2016, 4:34 p.m. UTC
From: Jiri Pirko <jiri@mellanox.com>

In order to not confuse reader, write help messages into stderr.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 46 +++++++++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

Comments

Stephen Hemminger July 23, 2016, 4:46 p.m. UTC | #1
On Fri, 22 Jul 2016 18:34:29 +0200
Jiri Pirko <jiri@resnulli.us> wrote:

> From: Jiri Pirko <jiri@mellanox.com>
> 
> In order to not confuse reader, write help messages into stderr.
> 
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>

This does make devlink consistent with other parts of iproute2.
But the most common coding standards, back to Unix, and GNU are
that help messages should go to stdout so that:
  $ ip -h | more
would work as expected.


 http://unix.stackexchange.com/questions/8813/should-the-usage-message-go-to-stderr-or-stdout/8815
 https://www.gnu.org/prep/standards/html_node/_002d_002dhelp.html
Jiri Pirko Aug. 8, 2016, 7:19 a.m. UTC | #2
Sat, Jul 23, 2016 at 06:46:59PM CEST, stephen@networkplumber.org wrote:
>On Fri, 22 Jul 2016 18:34:29 +0200
>Jiri Pirko <jiri@resnulli.us> wrote:
>
>> From: Jiri Pirko <jiri@mellanox.com>
>> 
>> In order to not confuse reader, write help messages into stderr.
>> 
>> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
>
>This does make devlink consistent with other parts of iproute2.
>But the most common coding standards, back to Unix, and GNU are
>that help messages should go to stdout so that:
>  $ ip -h | more
>would work as expected.

The thing is I wanted to make stdout only for json. Putting non-json
help out there does not look correct to me. Is it?
Stephen Hemminger Aug. 8, 2016, 3:56 p.m. UTC | #3
On Mon, 8 Aug 2016 09:19:21 +0200
Jiri Pirko <jiri@resnulli.us> wrote:

> Sat, Jul 23, 2016 at 06:46:59PM CEST, stephen@networkplumber.org wrote:
> >On Fri, 22 Jul 2016 18:34:29 +0200
> >Jiri Pirko <jiri@resnulli.us> wrote:
> >  
> >> From: Jiri Pirko <jiri@mellanox.com>
> >> 
> >> In order to not confuse reader, write help messages into stderr.
> >> 
> >> Signed-off-by: Jiri Pirko <jiri@mellanox.com>  
> >
> >This does make devlink consistent with other parts of iproute2.
> >But the most common coding standards, back to Unix, and GNU are
> >that help messages should go to stdout so that:
> >  $ ip -h | more
> >would work as expected.  
> 
> The thing is I wanted to make stdout only for json. Putting non-json
> help out there does not look correct to me. Is it?
> 

I applied both of these patches, just wanted to mention that iproute2 is not
following the GNU convention. At this point, it really doesn't matter, there
are arguments to be made for both behaviors.
Jiri Pirko Aug. 8, 2016, 4:18 p.m. UTC | #4
Mon, Aug 08, 2016 at 05:56:54PM CEST, stephen@networkplumber.org wrote:
>On Mon, 8 Aug 2016 09:19:21 +0200
>Jiri Pirko <jiri@resnulli.us> wrote:
>
>> Sat, Jul 23, 2016 at 06:46:59PM CEST, stephen@networkplumber.org wrote:
>> >On Fri, 22 Jul 2016 18:34:29 +0200
>> >Jiri Pirko <jiri@resnulli.us> wrote:
>> >  
>> >> From: Jiri Pirko <jiri@mellanox.com>
>> >> 
>> >> In order to not confuse reader, write help messages into stderr.
>> >> 
>> >> Signed-off-by: Jiri Pirko <jiri@mellanox.com>  
>> >
>> >This does make devlink consistent with other parts of iproute2.
>> >But the most common coding standards, back to Unix, and GNU are
>> >that help messages should go to stdout so that:
>> >  $ ip -h | more
>> >would work as expected.  
>> 
>> The thing is I wanted to make stdout only for json. Putting non-json
>> help out there does not look correct to me. Is it?
>> 
>
>I applied both of these patches, just wanted to mention that iproute2 is not
>following the GNU convention. At this point, it really doesn't matter, there
>are arguments to be made for both behaviors.


Allright. Thanks.
David Laight Aug. 9, 2016, 10:34 a.m. UTC | #5
From: Stephen Hemminger
> Sent: 08 August 2016 16:57
> To: Jiri Pirko
...
> > >> In order to not confuse reader, write help messages into stderr.
> > >>
> > >> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
> > >
> > >This does make devlink consistent with other parts of iproute2.
> > >But the most common coding standards, back to Unix, and GNU are
> > >that help messages should go to stdout so that:
> > >  $ ip -h | more
> > >would work as expected.
> >
> > The thing is I wanted to make stdout only for json. Putting non-json
> > help out there does not look correct to me. Is it?
> >
> 
> I applied both of these patches, just wanted to mention that iproute2 is not
> following the GNU convention. At this point, it really doesn't matter, there
> are arguments to be made for both behaviors.

If you output help in response to an invalid option (eg) 'ip -?' then you
need to write it to stderr since it is part of the error message.
OTOH if help is explicitly requested 'ip -h' then stdout would be ok.

Nothing wrong with typing 'ip -h 2>&1 | pg' though.

	David
diff mbox

Patch

diff --git a/devlink/devlink.c b/devlink/devlink.c
index ffefa86..f73ba95 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -909,7 +909,7 @@  static bool dl_dump_filter(struct dl *dl, struct nlattr **tb)
 
 static void cmd_dev_help(void)
 {
-	pr_out("Usage: devlink dev show [ DEV ]\n");
+	pr_err("Usage: devlink dev show [ DEV ]\n");
 }
 
 static void __pr_out_handle(const char *bus_name, const char *dev_name)
@@ -1024,10 +1024,10 @@  static int cmd_dev(struct dl *dl)
 
 static void cmd_port_help(void)
 {
-	pr_out("Usage: devlink port show [ DEV/PORT_INDEX ]\n");
-	pr_out("       devlink port set DEV/PORT_INDEX [ type { eth | ib | auto} ]\n");
-	pr_out("       devlink port split DEV/PORT_INDEX count COUNT\n");
-	pr_out("       devlink port unsplit DEV/PORT_INDEX\n");
+	pr_err("Usage: devlink port show [ DEV/PORT_INDEX ]\n");
+	pr_err("       devlink port set DEV/PORT_INDEX [ type { eth | ib | auto} ]\n");
+	pr_err("       devlink port split DEV/PORT_INDEX count COUNT\n");
+	pr_err("       devlink port unsplit DEV/PORT_INDEX\n");
 }
 
 static const char *port_type_name(uint32_t type)
@@ -1174,22 +1174,22 @@  static int cmd_port(struct dl *dl)
 
 static void cmd_sb_help(void)
 {
-	pr_out("Usage: devlink sb show [ DEV [ sb SB_INDEX ] ]\n");
-	pr_out("       devlink sb pool show [ DEV [ sb SB_INDEX ] pool POOL_INDEX ]\n");
-	pr_out("       devlink sb pool set DEV [ sb SB_INDEX ] pool POOL_INDEX\n");
-	pr_out("                           size POOL_SIZE thtype { static | dynamic }\n");
-	pr_out("       devlink sb port pool show [ DEV/PORT_INDEX [ sb SB_INDEX ]\n");
-	pr_out("                                   pool POOL_INDEX ]\n");
-	pr_out("       devlink sb port pool set DEV/PORT_INDEX [ sb SB_INDEX ]\n");
-	pr_out("                                pool POOL_INDEX th THRESHOLD\n");
-	pr_out("       devlink sb tc bind show [ DEV/PORT_INDEX [ sb SB_INDEX ] tc TC_INDEX\n");
-	pr_out("                                 type { ingress | egress } ]\n");
-	pr_out("       devlink sb tc bind set DEV/PORT_INDEX [ sb SB_INDEX ] tc TC_INDEX\n");
-	pr_out("                              type { ingress | egress } pool POOL_INDEX\n");
-	pr_out("                              th THRESHOLD\n");
-	pr_out("       devlink sb occupancy show { DEV | DEV/PORT_INDEX } [ sb SB_INDEX ]\n");
-	pr_out("       devlink sb occupancy snapshot DEV [ sb SB_INDEX ]\n");
-	pr_out("       devlink sb occupancy clearmax DEV [ sb SB_INDEX ]\n");
+	pr_err("Usage: devlink sb show [ DEV [ sb SB_INDEX ] ]\n");
+	pr_err("       devlink sb pool show [ DEV [ sb SB_INDEX ] pool POOL_INDEX ]\n");
+	pr_err("       devlink sb pool set DEV [ sb SB_INDEX ] pool POOL_INDEX\n");
+	pr_err("                           size POOL_SIZE thtype { static | dynamic }\n");
+	pr_err("       devlink sb port pool show [ DEV/PORT_INDEX [ sb SB_INDEX ]\n");
+	pr_err("                                   pool POOL_INDEX ]\n");
+	pr_err("       devlink sb port pool set DEV/PORT_INDEX [ sb SB_INDEX ]\n");
+	pr_err("                                pool POOL_INDEX th THRESHOLD\n");
+	pr_err("       devlink sb tc bind show [ DEV/PORT_INDEX [ sb SB_INDEX ] tc TC_INDEX\n");
+	pr_err("                                 type { ingress | egress } ]\n");
+	pr_err("       devlink sb tc bind set DEV/PORT_INDEX [ sb SB_INDEX ] tc TC_INDEX\n");
+	pr_err("                              type { ingress | egress } pool POOL_INDEX\n");
+	pr_err("                              th THRESHOLD\n");
+	pr_err("       devlink sb occupancy show { DEV | DEV/PORT_INDEX } [ sb SB_INDEX ]\n");
+	pr_err("       devlink sb occupancy snapshot DEV [ sb SB_INDEX ]\n");
+	pr_err("       devlink sb occupancy clearmax DEV [ sb SB_INDEX ]\n");
 }
 
 static void pr_out_sb(struct nlattr **tb)
@@ -1991,7 +1991,7 @@  static int cmd_mon_show(struct dl *dl)
 
 static void cmd_mon_help(void)
 {
-	pr_out("Usage: devlink monitor [ all | OBJECT-LIST ]\n"
+	pr_err("Usage: devlink monitor [ all | OBJECT-LIST ]\n"
 	       "where  OBJECT-LIST := { dev | port }\n");
 }
 
@@ -2010,7 +2010,7 @@  static int cmd_mon(struct dl *dl)
 
 static void help(void)
 {
-	pr_out("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
+	pr_err("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
 	       "where  OBJECT := { dev | port | sb | monitor }\n"
 	       "       OPTIONS := { -V[ersion] | -n[no-nice-names] }\n");
 }