Skip to content

Commit

Permalink
Fix rustpkg help handling
Browse files Browse the repository at this point in the history
In general, you could 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.

This commit attempts to fix this by making Help a real Command, and
making the handing of it explicit.
  • Loading branch information
eminence committed Jan 11, 2014
1 parent f411b94 commit e01abfe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/librustpkg/context.rs
Expand Up @@ -229,12 +229,13 @@ pub enum Command {
BuildCmd,
CleanCmd,
DoCmd,
HelpCmd,
InfoCmd,
InitCmd,
InstallCmd,
ListCmd,
PreferCmd,
TestCmd,
InitCmd,
UninstallCmd,
UnpreferCmd,
}
Expand All @@ -246,6 +247,7 @@ impl FromStr for Command {
&"build" => Some(BuildCmd),
&"clean" => Some(CleanCmd),
&"do" => Some(DoCmd),
&"help" => Some(HelpCmd),
&"info" => Some(InfoCmd),
&"install" => Some(InstallCmd),
&"list" => Some(ListCmd),
Expand Down
14 changes: 13 additions & 1 deletion src/librustpkg/lib.rs
Expand Up @@ -43,7 +43,7 @@ use workspace::{each_pkg_parent_workspace, pkg_parent_workspaces, cwd_to_workspa
use workspace::determine_destination;
use context::{BuildContext, Trans, Nothing, Pretty, Analysis,
LLVMAssemble, LLVMCompileBitcode};
use context::{Command, BuildCmd, CleanCmd, DoCmd, InfoCmd, InstallCmd, ListCmd,
use context::{Command, BuildCmd, CleanCmd, DoCmd, HelpCmd, InfoCmd, InstallCmd, ListCmd,
PreferCmd, TestCmd, InitCmd, UninstallCmd, UnpreferCmd};
use crate_id::CrateId;
use package_source::PkgSrc;
Expand Down Expand Up @@ -314,6 +314,18 @@ impl CtxMethods for BuildContext {

self.do_cmd(args[0].clone(), args[1].clone());
}
HelpCmd => {
if args.len() != 1 {
return usage::general();
}
match FromStr::from_str(args[0]) {
Some(help_cmd) => usage::usage_for_command(help_cmd),
None => {
usage::general();
error(format!("{} is not a recognized command", args[0]))
}
}
}
InfoCmd => {
self.info();
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustpkg/usage.rs
Expand Up @@ -16,6 +16,9 @@ pub fn general() {
Where <cmd> is one of:
build, clean, do, info, install, list, prefer, test, uninstall, unprefer
For more help on a given command, you can run:
rustpkg help <cmd>
Options:
-h, --help Display this message
Expand Down Expand Up @@ -162,6 +165,7 @@ pub fn usage_for_command(command: Command){
BuildCmd => build(),
CleanCmd => clean(),
DoCmd => do_cmd(),
HelpCmd => general(),
InfoCmd => info(),
InstallCmd => install(),
ListCmd => list(),
Expand Down

0 comments on commit e01abfe

Please sign in to comment.