Skip to content

Commit 584b405

Browse files
committed
Vastly improve the help output.
- Don't print 'unknown subcommand' at the top of the help message. The help message now clearly instructs the user to provide a subcommand. - Clarify the usage line. Subcommand is required. Don't echo invalid input back out in the usage line (what the...???). args renamed to paths, because that's what all the args are referred to elsewhere. - List the available subcommands immediately following the usage line. It's the one required argument, after all. - Slightly improve the extra documentation for the build, test, and doc commands. - Don't print 'Available invocations:' at all. It occurred immediately before 'Available paths:'. - Clearly state that running with '-h -v' will produce a list of available paths.
1 parent e1c1e09 commit 584b405

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/bootstrap/flags.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,31 @@ impl Flags {
9090
opts.optflag("h", "help", "print this help message");
9191

9292
let usage = |n, opts: &Options| -> ! {
93-
let subcommand = args.get(0).map(|s| &**s);
94-
let brief = format!("Usage: x.py <subcommand> [options] [<args>...]");
93+
let subcommand_help = format!("\
94+
Usage: x.py <subcommand> [options] [<paths>...]
95+
96+
Subcommands:
97+
build Compile either the compiler or libraries
98+
test Build and run some test suites
99+
bench Build and run some benchmarks
100+
doc Build documentation
101+
clean Clean out build directories
102+
dist Build and/or install distribution artifacts
95103
96-
println!("{}", opts.usage(&brief));
104+
To learn more about a subcommand, run `./x.py <subcommand> -h`");
105+
106+
println!("{}", opts.usage(&subcommand_help));
107+
108+
let subcommand = args.get(0).map(|s| &**s);
97109
match subcommand {
98110
Some("build") => {
99111
println!("\
100112
Arguments:
101-
This subcommand accepts a number of positional arguments of directories to
102-
the crates and/or artifacts to compile. For example:
113+
This subcommand accepts a number of paths to directories to the crates
114+
and/or artifacts to compile. For example:
103115
104116
./x.py build src/libcore
105-
./x.py build src/libproc_macro
117+
./x.py build src/libcore src/libproc_macro
106118
./x.py build src/libstd --stage 1
107119
108120
If no arguments are passed then the complete artifacts for that stage are
@@ -120,8 +132,8 @@ Arguments:
120132
Some("test") => {
121133
println!("\
122134
Arguments:
123-
This subcommand accepts a number of positional arguments of directories to
124-
tests that should be compiled and run. For example:
135+
This subcommand accepts a number of paths to directories to tests that
136+
should be compiled and run. For example:
125137
126138
./x.py test src/test/run-pass
127139
./x.py test src/libstd --test-args hash_map
@@ -138,12 +150,12 @@ Arguments:
138150
Some("doc") => {
139151
println!("\
140152
Arguments:
141-
This subcommand accepts a number of positional arguments of directories of
142-
documentation to build. For example:
153+
This subcommand accepts a number of paths to directories of documentation
154+
to build. For example:
143155
144156
./x.py doc src/doc/book
145157
./x.py doc src/doc/nomicon
146-
./x.py doc src/libstd
158+
./x.py doc src/doc/book src/libstd
147159
148160
If no arguments are passed then everything is documented:
149161
@@ -155,14 +167,14 @@ Arguments:
155167
_ => {}
156168
}
157169

170+
158171
if let Some(subcommand) = subcommand {
159172
if subcommand == "build" ||
160173
subcommand == "test" ||
161174
subcommand == "bench" ||
162175
subcommand == "doc" ||
163176
subcommand == "clean" ||
164177
subcommand == "dist" {
165-
println!("Available invocations:");
166178
if args.iter().any(|a| a == "-v") {
167179
let flags = Flags::parse(&["build".to_string()]);
168180
let mut config = Config::default();
@@ -171,26 +183,14 @@ Arguments:
171183
metadata::build(&mut build);
172184
step::build_rules(&build).print_help(subcommand);
173185
} else {
174-
println!(" ... elided, run `./x.py {} -h -v` to see",
186+
println!("Run `./x.py {} -h -v` to see a list of available paths.",
175187
subcommand);
176188
}
177189

178190
println!("");
179191
}
180192
}
181193

182-
println!("\
183-
Subcommands:
184-
build Compile either the compiler or libraries
185-
test Build and run some test suites
186-
bench Build and run some benchmarks
187-
doc Build documentation
188-
clean Clean out build directories
189-
dist Build and/or install distribution artifacts
190-
191-
To learn more about a subcommand, run `./x.py <subcommand> -h`
192-
");
193-
194194
process::exit(n);
195195
};
196196
if args.len() == 0 {
@@ -256,8 +256,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`
256256
}
257257
}
258258
"--help" => usage(0, &opts),
259-
cmd => {
260-
println!("unknown subcommand: {}", cmd);
259+
_ => {
261260
usage(1, &opts);
262261
}
263262
};

0 commit comments

Comments
 (0)