From aa05d158e86e99237178dc3c8ae09ca5eb6c166b Mon Sep 17 00:00:00 2001 From: Cole Miller Date: Fri, 12 Mar 2021 12:31:13 -0500 Subject: [PATCH] Print usage message to standard error, not standard output This is more appropriate for human-directed output that generally shouldn't end up in pipelines, etc. --- src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0627a9b..893ed0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,7 +273,7 @@ pub trait Options { /// process will exit with status code `2`. /// /// If the user supplies a help option, option usage will be printed to - /// `stdout` and the process will exit with status code `0`. + /// `stderr` and the process will exit with status code `0`. /// /// Otherwise, the parsed options are returned. fn parse_args_or_exit(style: ParsingStyle) -> Self where Self: Sized { @@ -304,14 +304,14 @@ pub trait Options { } } - println!("Usage: {}{} [OPTIONS]", args[0], command_str); - println!(); - println!("{}", command.self_usage()); + eprintln!("Usage: {}{} [OPTIONS]", args[0], command_str); + eprintln!(); + eprintln!("{}", command.self_usage()); if let Some(cmds) = command.self_command_list() { - println!(); - println!("Available commands:"); - println!("{}", cmds); + eprintln!(); + eprintln!("Available commands:"); + eprintln!("{}", cmds); } exit(0); @@ -327,7 +327,7 @@ pub trait Options { /// process will exit with status code `2`. /// /// If the user supplies a help option, option usage will be printed to - /// `stdout` and the process will exit with status code `0`. + /// `stderr` and the process will exit with status code `0`. /// /// Otherwise, the parsed options are returned. fn parse_args_default_or_exit() -> Self where Self: Sized { @@ -695,7 +695,7 @@ pub fn parse_args_default(args: &[String]) -> Result { /// process will exit with status code `2`. /// /// If the user supplies a help option, option usage will be printed to -/// `stdout` and the process will exit with status code `0`. +/// `stderr` and the process will exit with status code `0`. /// /// Otherwise, the parsed options are returned. /// @@ -713,7 +713,7 @@ pub fn parse_args_or_exit(style: ParsingStyle) -> T { /// process will exit with status code `2`. /// /// If the user supplies a help option, option usage will be printed to -/// `stdout` and the process will exit with status code `0`. +/// `stderr` and the process will exit with status code `0`. /// /// Otherwise, the parsed options are returned. ///