Move publish to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 8 Mar 2018 08:49:31 +0000 (11:49 +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/publish.rs [new file with mode: 0644]

index 5efdd34a266ab1d9741a1eb7bf7838b6233760de..9a9b010b8f5381dcfbc4d077e65933d9ff706fbf 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" | "pkgid"=> true,
+        "owner" | "package" | "pkgid" | "publish" => true,
         _ => false
     });
 
@@ -137,7 +137,7 @@ macro_rules! each_subcommand{
 //        $mac!(owner);
 //        $mac!(package);
 //        $mac!(pkgid);
-        $mac!(publish);
+//        $mac!(publish);
         $mac!(read_manifest);
         $mac!(run);
         $mac!(rustc);
index 89114bca7f064b85fc26a17bfdf56db4d203acf9..86459623b69931e09fe75784c3bc7d6b9eae17cd 100644 (file)
@@ -407,6 +407,47 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> {
             println!("{}", spec);
             Ok(())
         }
+        ("publish", Some(args)) => {
+            let registry = registry_from_args(config, args)?;
+            let ws = workspace_from_args(config, args)?;
+
+            // TODO: Deprecated
+            // remove once it has been decided --host can be removed
+            // We may instead want to repurpose the host flag, as
+            // mentioned in this issue
+            // https://github.com/rust-lang/cargo/issues/4208
+            let msg = "The flag '--host' is no longer valid.
+
+Previous versions of Cargo accepted this flag, but it is being
+deprecated. The flag is being renamed to 'index', as the flag
+wants the location of the index to which to publish. Please
+use '--index' instead.
+
+This will soon become a hard error, so it's either recommended
+to update to a fixed version or contact the upstream maintainer
+about this warning.";
+
+            let index = match args.value_of("host") {
+                Some(host) => {
+                    config.shell().warn(&msg)?;
+                    Some(host.to_string())
+                }
+                None => args.value_of("index").map(|s| s.to_string())
+            };
+
+            ops::publish(&ws, &ops::PublishOpts {
+                config,
+                token: args.value_of("token").map(|s| s.to_string()),
+                index,
+                verify: !args.is_present("no-verify"),
+                allow_dirty: args.is_present("allow-dirty"),
+                target: args.value_of("target"),
+                jobs: jobs_from_args(args),
+                dry_run: args.is_present("dry-run"),
+                registry,
+            })?;
+            return Ok(());
+        }
         _ => return Ok(())
     }
 }
@@ -493,6 +534,7 @@ See 'cargo help <command>' for more information on a specific command.
             owner::cli(),
             package::cli(),
             pkgid::cli(),
+            publish::cli(),
         ])
     ;
     app
@@ -518,6 +560,7 @@ mod new;
 mod owner;
 mod package;
 mod pkgid;
+mod publish;
 
 mod utils {
     use clap::{self, SubCommand, AppSettings};
diff --git a/src/bin/cli/publish.rs b/src/bin/cli/publish.rs
new file mode 100644 (file)
index 0000000..17ffa97
--- /dev/null
@@ -0,0 +1,25 @@
+use super::utils::*;
+
+pub fn cli() -> App {
+    subcommand("publish")
+        .about("Upload a package to the registry")
+        .arg(
+            opt("index", "Registry index to upload the package to")
+                .value_name("INDEX")
+        )
+        .arg(
+            opt("host", "DEPRECATED, renamed to '--index'")
+                .value_name("HOST")
+                .hidden(true)
+        )
+        .arg(opt("token", "Token to use when uploading").value_name("TOKEN"))
+        .arg(opt("no-verify", "Don't verify the contents by building them"))
+        .arg(opt("allow-dirty", "Allow dirty working directories to be packaged"))
+        .arg_target_triple("Build for the target triple")
+        .arg_manifest_path()
+        .arg_jobs()
+        .arg(
+            opt("dry-run", "Perform all checks without uploading")
+        )
+        .arg(opt("registry", "Registry to publish to").value_name("REGISTRY"))
+}