Skip to content

Make help message more consistent (capitalization and indentation) #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ what we have now::

$ rustc greeting.rs
$ ./greeting -h
Usage: ./greeting [OPTIONS]
Usage:
./greeting [OPTIONS]

Greet somebody.

optional arguments:
-h, --help show this help message and exit
-v, --verbose
Optional arguments:
-h, --help show this help message and exit
-v, --verbose
Be verbose
--name NAME Name for the greeting
--name NAME Name for the greeting
$ ./greeting
Hello World!
$ ./greeting --name Bob
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ impl<'a, 'b> HelpFormatter<'a, 'b> {
if self.parser.arguments.len() > 0
|| self.parser.catchall_argument.is_some()
{
try!(write!(self.buf, "\npositional arguments:\n"));
try!(write!(self.buf, "\nPositional arguments:\n"));
for arg in self.parser.arguments.iter() {
try!(self.print_argument(&**arg));
}
Expand All @@ -911,7 +911,7 @@ impl<'a, 'b> HelpFormatter<'a, 'b> {
if self.parser.short_options.len() > 0
|| self.parser.long_options.len() > 0
{
try!(write!(self.buf, "\noptional arguments:\n"));
try!(write!(self.buf, "\nOptional arguments:\n"));
for opt in self.parser.options.iter() {
try!(self.print_option(&**opt));
}
Expand All @@ -920,7 +920,7 @@ impl<'a, 'b> HelpFormatter<'a, 'b> {
}

fn write_usage(&mut self) -> IoResult<()> {
try!(write!(self.buf, "Usage:\n "));
try!(write!(self.buf, "Usage:\n "));
try!(write!(self.buf, "{}", self.name));
if self.parser.options.len() != 0 {
if self.parser.short_options.len() > 1
Expand Down
30 changes: 15 additions & 15 deletions src/test_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ fn test_empty() {
ap.set_description("Test program");
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n".to_string()
+ " ./argparse_test\n"
+ " ./argparse_test\n"
+ "\n"
+ "Test program\n"
+ "\n"
+ "optional arguments:\n"
+ "Optional arguments:\n"
+ " -h,--help show this help message and exit\n"
, from_utf8(&buf[..]).unwrap().to_string());
}
Expand All @@ -36,13 +36,13 @@ fn test_options() {
let mut buf = Vec::<u8>::new();
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n".to_string()
+ " ./argparse_test [OPTIONS]
+ " ./argparse_test [OPTIONS]

Test program. The description of the program is ought to be very long, because
we want to test how word wrapping works for it. So some more text would be ok
for the test\n"
+ "\n"
+ "optional arguments:\n"
+ "Optional arguments:\n"
+ " -h,--help show this help message and exit\n"
+ " --value VALUE Set integer value\n"
+ " -L,--long-option LONG_OPTION\n"
Expand All @@ -61,14 +61,14 @@ fn test_argument() {
let mut buf = Vec::<u8>::new();
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n".to_string()
+ " ./argparse_test [VALUE]\n"
+ " ./argparse_test [VALUE]\n"
+ "\n"
+ "Test program\n"
+ "\n"
+ "positional arguments:\n"
+ "Positional arguments:\n"
+ " value Integer value\n"
+ "\n"
+ "optional arguments:\n"
+ "Optional arguments:\n"
+ " -h,--help show this help message and exit\n"
, from_utf8(&buf[..]).unwrap().to_string());
}
Expand All @@ -88,15 +88,15 @@ fn test_arguments() {
let mut buf = Vec::<u8>::new();
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n".to_string()
+ " ./argparse_test [V1] [V2 ...]\n"
+ " ./argparse_test [V1] [V2 ...]\n"
+ "\n"
+ "Test program\n"
+ "\n"
+ "positional arguments:\n"
+ "Positional arguments:\n"
+ " v1 Integer value 1\n"
+ " v2 More values\n"
+ "\n"
+ "optional arguments:\n"
+ "Optional arguments:\n"
+ " -h,--help show this help message and exit\n"
, from_utf8(&buf[..]).unwrap().to_string());
}
Expand All @@ -118,15 +118,15 @@ fn test_req_arguments() {
let mut buf = Vec::<u8>::new();
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n".to_string()
+ " ./argparse_test V1 V2 [...]\n"
+ " ./argparse_test V1 V2 [...]\n"
+ "\n"
+ "Test program\n"
+ "\n"
+ "positional arguments:\n"
+ "Positional arguments:\n"
+ " v1 Integer value 1\n"
+ " v2 More values\n"
+ "\n"
+ "optional arguments:\n"
+ "Optional arguments:\n"
+ " -h,--help show this help message and exit\n"
, from_utf8(&buf[..]).unwrap().to_string());
}
Expand All @@ -143,11 +143,11 @@ fn test_metavar() {
let mut buf = Vec::<u8>::new();
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n".to_string()
+ " ./argparse_test [OPTIONS]\n"
+ " ./argparse_test [OPTIONS]\n"
+ "\n"
+ "Test program.\n"
+ "\n"
+ "optional arguments:\n"
+ "Optional arguments:\n"
+ " -h,--help show this help message and exit\n"
+ " -L,--long-option VAL Long option value\n"
, from_utf8(&buf[..]).unwrap().to_string());
Expand Down
8 changes: 4 additions & 4 deletions src/test_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn test_empty() {
let ap = ArgumentParser::new();
let mut buf = Vec::<u8>::new();
assert!(ap.print_usage("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n ./argparse_test\n", from_utf8(&buf[..]).unwrap());
assert_eq!("Usage:\n ./argparse_test\n", from_utf8(&buf[..]).unwrap());
}

#[test]
Expand All @@ -22,7 +22,7 @@ fn test_options() {
"Set integer value");
assert!(ap.print_usage("./argparse_test", &mut buf).is_ok());
}
assert_eq!("Usage:\n ./argparse_test [OPTIONS]\n",
assert_eq!("Usage:\n ./argparse_test [OPTIONS]\n",
from_utf8(&buf[..]).unwrap());
}

Expand All @@ -35,7 +35,7 @@ fn test_argument() {
"Integer value");
let mut buf = Vec::<u8>::new();
assert!(ap.print_usage("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n ./argparse_test [VALUE]\n",
assert_eq!("Usage:\n ./argparse_test [VALUE]\n",
from_utf8(&buf[..]).unwrap());
}

Expand All @@ -52,6 +52,6 @@ fn test_arguments() {
"More values");
let mut buf = Vec::<u8>::new();
assert!(ap.print_usage("./argparse_test", &mut buf).is_ok());
assert_eq!("Usage:\n ./argparse_test [V1] [V2 ...]\n",
assert_eq!("Usage:\n ./argparse_test [V1] [V2 ...]\n",
from_utf8(&buf[..]).unwrap());
}