about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-01-11 10:21:22 -0800
committerbors <bors@rust-lang.org>2014-01-11 10:21:22 -0800
commit91aec7c8a65db0768fdccc29706cba731101f7fc (patch)
tree8994b45e73cec6cd7ac674bab82e7c1785c00dc7
parent29e82c65b47130fb431aaca0b33935ecfcd09d85 (diff)
parentdc21ca98331f181fabefe25f31464ff920f805fd (diff)
downloadrust-91aec7c8a65db0768fdccc29706cba731101f7fc.tar.gz
rust-91aec7c8a65db0768fdccc29706cba731101f7fc.zip
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)
-rw-r--r--src/librustpkg/context.rs4
-rw-r--r--src/librustpkg/lib.rs16
-rw-r--r--src/librustpkg/usage.rs4
3 files changed, 21 insertions, 3 deletions
diff --git a/src/librustpkg/context.rs b/src/librustpkg/context.rs
index 51b42869c75..5362ca2c932 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 3d2ef2ebaba..3a5c79a62ab 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();
             }
@@ -372,7 +384,7 @@ impl CtxMethods for BuildContext {
             }
             PreferCmd => {
                 if args.len() < 1 {
-                    return usage::uninstall();
+                    return usage::prefer();
                 }
 
                 self.prefer(args[0], None);
diff --git a/src/librustpkg/usage.rs b/src/librustpkg/usage.rs
index 6fcafac4e5b..04cc13d0650 100644
--- a/src/librustpkg/usage.rs
+++ b/src/librustpkg/usage.rs
@@ -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
@@ -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(),