From e01abfe432be4bba7a41f7fe1af6656930e19271 Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Sat, 11 Jan 2014 00:34:09 -0500 Subject: [PATCH 1/2] Fix `rustpkg help` handling In general, you could run "rustpkg help " to see some specific usage information for . 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. --- src/librustpkg/context.rs | 4 +++- src/librustpkg/lib.rs | 14 +++++++++++++- src/librustpkg/usage.rs | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/librustpkg/context.rs b/src/librustpkg/context.rs index 681ae1dc807..721cfedd4aa 100644 --- a/src/librustpkg/context.rs +++ b/src/librustpkg/context.rs @@ -229,12 +229,13 @@ pub enum Command { BuildCmd, CleanCmd, DoCmd, + HelpCmd, InfoCmd, + InitCmd, InstallCmd, ListCmd, PreferCmd, TestCmd, - InitCmd, UninstallCmd, UnpreferCmd, } @@ -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), diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index 135b659871d..538865acfb5 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -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; @@ -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(); } diff --git a/src/librustpkg/usage.rs b/src/librustpkg/usage.rs index a41e99f6d66..ccc0beafd71 100644 --- a/src/librustpkg/usage.rs +++ b/src/librustpkg/usage.rs @@ -16,6 +16,9 @@ pub fn general() { Where 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 + Options: -h, --help Display this message @@ -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(), From dc21ca98331f181fabefe25f31464ff920f805fd Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Sat, 11 Jan 2014 11:48:54 -0500 Subject: [PATCH 2/2] "rustpkg prefer" should print the help for '"prefer" not "uninstall" --- src/librustpkg/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustpkg/lib.rs b/src/librustpkg/lib.rs index 538865acfb5..27d3a3e549a 100644 --- a/src/librustpkg/lib.rs +++ b/src/librustpkg/lib.rs @@ -384,7 +384,7 @@ impl CtxMethods for BuildContext { } PreferCmd => { if args.len() < 1 { - return usage::uninstall(); + return usage::prefer(); } self.prefer(args[0], None);