Skip to content

Commit 91aec7c

Browse files
committed
auto merge of #11470 : eminence/rust/rustpkg_help_test, r=alexcrichton
In general, you can run "rustpkg help <cmd>" to see some specific usage information for <cmd>. However, this was handled in a very ad-hoc and buggy manner. For example, running "rustpkg help prefer" would actually show you the usage information for the "uninstall" cmd. Or "rustpkg help test" would show you the usage information for the "build" command. Or "rustpkg help list" would just run the "list" command (and not show you anything usage information) This commit attempts to fix this by making a new HelpCmd (and handling it explicitly)
2 parents 29e82c6 + dc21ca9 commit 91aec7c

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/librustpkg/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,13 @@ pub enum Command {
229229
BuildCmd,
230230
CleanCmd,
231231
DoCmd,
232+
HelpCmd,
232233
InfoCmd,
234+
InitCmd,
233235
InstallCmd,
234236
ListCmd,
235237
PreferCmd,
236238
TestCmd,
237-
InitCmd,
238239
UninstallCmd,
239240
UnpreferCmd,
240241
}
@@ -246,6 +247,7 @@ impl FromStr for Command {
246247
&"build" => Some(BuildCmd),
247248
&"clean" => Some(CleanCmd),
248249
&"do" => Some(DoCmd),
250+
&"help" => Some(HelpCmd),
249251
&"info" => Some(InfoCmd),
250252
&"install" => Some(InstallCmd),
251253
&"list" => Some(ListCmd),

src/librustpkg/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces, cwd_to_workspa
4343
use workspace::determine_destination;
4444
use context::{BuildContext, Trans, Nothing, Pretty, Analysis,
4545
LLVMAssemble, LLVMCompileBitcode};
46-
use context::{Command, BuildCmd, CleanCmd, DoCmd, InfoCmd, InstallCmd, ListCmd,
46+
use context::{Command, BuildCmd, CleanCmd, DoCmd, HelpCmd, InfoCmd, InstallCmd, ListCmd,
4747
PreferCmd, TestCmd, InitCmd, UninstallCmd, UnpreferCmd};
4848
use crate_id::CrateId;
4949
use package_source::PkgSrc;
@@ -314,6 +314,18 @@ impl CtxMethods for BuildContext {
314314

315315
self.do_cmd(args[0].clone(), args[1].clone());
316316
}
317+
HelpCmd => {
318+
if args.len() != 1 {
319+
return usage::general();
320+
}
321+
match FromStr::from_str(args[0]) {
322+
Some(help_cmd) => usage::usage_for_command(help_cmd),
323+
None => {
324+
usage::general();
325+
error(format!("{} is not a recognized command", args[0]))
326+
}
327+
}
328+
}
317329
InfoCmd => {
318330
self.info();
319331
}
@@ -372,7 +384,7 @@ impl CtxMethods for BuildContext {
372384
}
373385
PreferCmd => {
374386
if args.len() < 1 {
375-
return usage::uninstall();
387+
return usage::prefer();
376388
}
377389

378390
self.prefer(args[0], None);

src/librustpkg/usage.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub fn general() {
1616
Where <cmd> is one of:
1717
build, clean, do, info, install, list, prefer, test, uninstall, unprefer
1818
19+
For more help on a given command, you can run:
20+
rustpkg help <cmd>
21+
1922
Options:
2023
2124
-h, --help Display this message
@@ -162,6 +165,7 @@ pub fn usage_for_command(command: Command){
162165
BuildCmd => build(),
163166
CleanCmd => clean(),
164167
DoCmd => do_cmd(),
168+
HelpCmd => general(),
165169
InfoCmd => info(),
166170
InstallCmd => install(),
167171
ListCmd => list(),

0 commit comments

Comments
 (0)