Move pkgid to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 7 Mar 2018 15:02:36 +0000 (18:02 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 8 Mar 2018 20:30:46 +0000 (23:30 +0300)
src/bin/cargo.rs
src/bin/cli/mod.rs
src/bin/cli/pkgid.rs [new file with mode: 0644]

index bb7e9319e2acc5b0fbfc1e85b2d24443f3dacf4f..5efdd34a266ab1d9741a1eb7bf7838b6233760de 100644 (file)
@@ -91,7 +91,7 @@ fn main() {
     let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() {
         "build" | "bench" | "check" | "clean" | "doc" | "fetch" | "generate-lockfile" | "git-checkout" |
         "init" | "install" | "locate-project" | "login" | "metadata" | "new" |
-        "owner" | "package" => true,
+        "owner" | "package" | "pkgid"=> true,
         _ => false
     });
 
@@ -136,7 +136,7 @@ macro_rules! each_subcommand{
 //        $mac!(new);
 //        $mac!(owner);
 //        $mac!(package);
-        $mac!(pkgid);
+//        $mac!(pkgid);
         $mac!(publish);
         $mac!(read_manifest);
         $mac!(run);
index e2dbbb1fd87ea7037db8e9bad552c5e7a015a019..89114bca7f064b85fc26a17bfdf56db4d203acf9 100644 (file)
@@ -400,6 +400,13 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> {
             })?;
             return Ok(());
         }
+        ("pkgid", Some(args)) => {
+            let ws = workspace_from_args(config, args)?;
+            let spec = args.value_of("spec").or(args.value_of("package"));
+            let spec = ops::pkgid(&ws, spec)?;
+            println!("{}", spec);
+            Ok(())
+        }
         _ => return Ok(())
     }
 }
@@ -485,6 +492,7 @@ See 'cargo help <command>' for more information on a specific command.
             new::cli(),
             owner::cli(),
             package::cli(),
+            pkgid::cli(),
         ])
     ;
     app
@@ -509,6 +517,7 @@ mod metadata;
 mod new;
 mod owner;
 mod package;
+mod pkgid;
 
 mod utils {
     use clap::{self, SubCommand, AppSettings};
diff --git a/src/bin/cli/pkgid.rs b/src/bin/cli/pkgid.rs
new file mode 100644 (file)
index 0000000..5c4cd84
--- /dev/null
@@ -0,0 +1,32 @@
+use super::utils::*;
+
+pub fn cli() -> App {
+    subcommand("pkgid")
+        .about("Print a fully qualified package specification")
+        .arg(Arg::with_name("spec"))
+        .arg(
+            opt("package", "Argument to get the package id specifier for")
+                .short("p").value_name("SPEC")
+        )
+        .arg_manifest_path()
+        .after_help("\
+Given a <spec> argument, print out the fully qualified package id specifier.
+This command will generate an error if <spec> is ambiguous as to which package
+it refers to in the dependency graph. If no <spec> is given, then the pkgid for
+the local package is printed.
+
+This command requires that a lockfile is available and dependencies have been
+fetched.
+
+Example Package IDs
+
+           pkgid                  |  name  |  version  |          url
+    |-----------------------------|--------|-----------|---------------------|
+     foo                          | foo    | *         | *
+     foo:1.2.3                    | foo    | 1.2.3     | *
+     crates.io/foo                | foo    | *         | *://crates.io/foo
+     crates.io/foo#1.2.3          | foo    | 1.2.3     | *://crates.io/foo
+     crates.io/bar#foo:1.2.3      | foo    | 1.2.3     | *://crates.io/bar
+     http://crates.io/foo#1.2.3   | foo    | 1.2.3     | http://crates.io/foo
+")
+}