Skip to content

Commit 2eac7bc

Browse files
authored
Merge pull request #38 from jirutka/patch-1
Make help message more consistent (capitalization and indentation)
2 parents 8cc631a + 699af99 commit 2eac7bc

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@ what we have now::
5959

6060
$ rustc greeting.rs
6161
$ ./greeting -h
62-
Usage: ./greeting [OPTIONS]
62+
Usage:
63+
./greeting [OPTIONS]
6364

6465
Greet somebody.
6566

66-
optional arguments:
67-
-h, --help show this help message and exit
68-
-v, --verbose
67+
Optional arguments:
68+
-h, --help show this help message and exit
69+
-v, --verbose
6970
Be verbose
70-
--name NAME Name for the greeting
71+
--name NAME Name for the greeting
7172
$ ./greeting
7273
Hello World!
7374
$ ./greeting --name Bob

src/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ impl<'a, 'b> HelpFormatter<'a, 'b> {
897897
if self.parser.arguments.len() > 0
898898
|| self.parser.catchall_argument.is_some()
899899
{
900-
try!(write!(self.buf, "\npositional arguments:\n"));
900+
try!(write!(self.buf, "\nPositional arguments:\n"));
901901
for arg in self.parser.arguments.iter() {
902902
try!(self.print_argument(&**arg));
903903
}
@@ -911,7 +911,7 @@ impl<'a, 'b> HelpFormatter<'a, 'b> {
911911
if self.parser.short_options.len() > 0
912912
|| self.parser.long_options.len() > 0
913913
{
914-
try!(write!(self.buf, "\noptional arguments:\n"));
914+
try!(write!(self.buf, "\nOptional arguments:\n"));
915915
for opt in self.parser.options.iter() {
916916
try!(self.print_option(&**opt));
917917
}
@@ -920,7 +920,7 @@ impl<'a, 'b> HelpFormatter<'a, 'b> {
920920
}
921921

922922
fn write_usage(&mut self) -> IoResult<()> {
923-
try!(write!(self.buf, "Usage:\n "));
923+
try!(write!(self.buf, "Usage:\n "));
924924
try!(write!(self.buf, "{}", self.name));
925925
if self.parser.options.len() != 0 {
926926
if self.parser.short_options.len() > 1

src/test_help.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ fn test_empty() {
1010
ap.set_description("Test program");
1111
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
1212
assert_eq!("Usage:\n".to_string()
13-
+ " ./argparse_test\n"
13+
+ " ./argparse_test\n"
1414
+ "\n"
1515
+ "Test program\n"
1616
+ "\n"
17-
+ "optional arguments:\n"
17+
+ "Optional arguments:\n"
1818
+ " -h,--help show this help message and exit\n"
1919
, from_utf8(&buf[..]).unwrap().to_string());
2020
}
@@ -36,13 +36,13 @@ fn test_options() {
3636
let mut buf = Vec::<u8>::new();
3737
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
3838
assert_eq!("Usage:\n".to_string()
39-
+ " ./argparse_test [OPTIONS]
39+
+ " ./argparse_test [OPTIONS]
4040
4141
Test program. The description of the program is ought to be very long, because
4242
we want to test how word wrapping works for it. So some more text would be ok
4343
for the test\n"
4444
+ "\n"
45-
+ "optional arguments:\n"
45+
+ "Optional arguments:\n"
4646
+ " -h,--help show this help message and exit\n"
4747
+ " --value VALUE Set integer value\n"
4848
+ " -L,--long-option LONG_OPTION\n"
@@ -61,14 +61,14 @@ fn test_argument() {
6161
let mut buf = Vec::<u8>::new();
6262
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
6363
assert_eq!("Usage:\n".to_string()
64-
+ " ./argparse_test [VALUE]\n"
64+
+ " ./argparse_test [VALUE]\n"
6565
+ "\n"
6666
+ "Test program\n"
6767
+ "\n"
68-
+ "positional arguments:\n"
68+
+ "Positional arguments:\n"
6969
+ " value Integer value\n"
7070
+ "\n"
71-
+ "optional arguments:\n"
71+
+ "Optional arguments:\n"
7272
+ " -h,--help show this help message and exit\n"
7373
, from_utf8(&buf[..]).unwrap().to_string());
7474
}
@@ -88,15 +88,15 @@ fn test_arguments() {
8888
let mut buf = Vec::<u8>::new();
8989
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
9090
assert_eq!("Usage:\n".to_string()
91-
+ " ./argparse_test [V1] [V2 ...]\n"
91+
+ " ./argparse_test [V1] [V2 ...]\n"
9292
+ "\n"
9393
+ "Test program\n"
9494
+ "\n"
95-
+ "positional arguments:\n"
95+
+ "Positional arguments:\n"
9696
+ " v1 Integer value 1\n"
9797
+ " v2 More values\n"
9898
+ "\n"
99-
+ "optional arguments:\n"
99+
+ "Optional arguments:\n"
100100
+ " -h,--help show this help message and exit\n"
101101
, from_utf8(&buf[..]).unwrap().to_string());
102102
}
@@ -118,15 +118,15 @@ fn test_req_arguments() {
118118
let mut buf = Vec::<u8>::new();
119119
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
120120
assert_eq!("Usage:\n".to_string()
121-
+ " ./argparse_test V1 V2 [...]\n"
121+
+ " ./argparse_test V1 V2 [...]\n"
122122
+ "\n"
123123
+ "Test program\n"
124124
+ "\n"
125-
+ "positional arguments:\n"
125+
+ "Positional arguments:\n"
126126
+ " v1 Integer value 1\n"
127127
+ " v2 More values\n"
128128
+ "\n"
129-
+ "optional arguments:\n"
129+
+ "Optional arguments:\n"
130130
+ " -h,--help show this help message and exit\n"
131131
, from_utf8(&buf[..]).unwrap().to_string());
132132
}
@@ -143,11 +143,11 @@ fn test_metavar() {
143143
let mut buf = Vec::<u8>::new();
144144
assert!(ap.print_help("./argparse_test", &mut buf).is_ok());
145145
assert_eq!("Usage:\n".to_string()
146-
+ " ./argparse_test [OPTIONS]\n"
146+
+ " ./argparse_test [OPTIONS]\n"
147147
+ "\n"
148148
+ "Test program.\n"
149149
+ "\n"
150-
+ "optional arguments:\n"
150+
+ "Optional arguments:\n"
151151
+ " -h,--help show this help message and exit\n"
152152
+ " -L,--long-option VAL Long option value\n"
153153
, from_utf8(&buf[..]).unwrap().to_string());

src/test_usage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn test_empty() {
88
let ap = ArgumentParser::new();
99
let mut buf = Vec::<u8>::new();
1010
assert!(ap.print_usage("./argparse_test", &mut buf).is_ok());
11-
assert_eq!("Usage:\n ./argparse_test\n", from_utf8(&buf[..]).unwrap());
11+
assert_eq!("Usage:\n ./argparse_test\n", from_utf8(&buf[..]).unwrap());
1212
}
1313

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

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

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

0 commit comments

Comments
 (0)