Move command_prelude to a separate file
authorAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 10 Mar 2018 13:16:00 +0000 (16:16 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Sat, 10 Mar 2018 13:16:00 +0000 (16:16 +0300)
31 files changed:
src/bin/cargo.rs
src/bin/cli/bench.rs
src/bin/cli/build.rs
src/bin/cli/check.rs
src/bin/cli/clean.rs
src/bin/cli/doc.rs
src/bin/cli/fetch.rs
src/bin/cli/generate_lockfile.rs
src/bin/cli/git_checkout.rs
src/bin/cli/init.rs
src/bin/cli/install.rs
src/bin/cli/locate_project.rs
src/bin/cli/login.rs
src/bin/cli/metadata.rs
src/bin/cli/mod.rs
src/bin/cli/new.rs
src/bin/cli/owner.rs
src/bin/cli/package.rs
src/bin/cli/pkgid.rs
src/bin/cli/publish.rs
src/bin/cli/read_manifest.rs
src/bin/cli/run.rs
src/bin/cli/rustc.rs
src/bin/cli/rustdoc.rs
src/bin/cli/search.rs
src/bin/cli/test.rs
src/bin/cli/uninstall.rs
src/bin/cli/update.rs
src/bin/cli/verify_project.rs
src/bin/cli/version.rs
src/bin/cli/yank.rs

index 27c751d3addd780d796101cb1f9ca91e89e48413..b7aa9a4125cf8c970bd84a06bd83851ab966c61f 100644 (file)
@@ -19,6 +19,8 @@ use cargo::util::{self, CliResult, lev_distance, Config, CargoResult};
 use cargo::util::{CliError, ProcessError};
 
 mod cli;
+mod command_prelude;
+
 
 fn main() {
     env_logger::init();
index 58a73b4edec058075722865dfe54cad62a971779..df43b78018d8d8791dbb26cf6d2c8096eb9cb3bb 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 use clap::AppSettings;
 
 pub fn cli() -> App {
index 2d1bdd921325816d9544671222914eb754244240..9eddd651b085856d0fa67c9bee19aabc9f863ca4 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("build").alias("b")
index 2777f2317a8239b57cabd172efcc60a1cfcc5356..ecf7fe6cea7774fc95736a1ae0ab4afaecb0e434 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("check")
index e23eac7adb64956d2d85a728c156498a6efb57c3..7852c3c5c9796c3a7252c0f1b559517ed54d0dbe 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("clean")
index ddf76081a1ccd7f6acec73e3aea6688f7d522702..bcb709b2934b0c201a6780c864676d76d3002d46 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("doc")
index 39b08ab935afa831f8e8eb07f384cf6632fa3ca7..bb4a946ab5e406945422b24440fc5b5ba7b9a4f6 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("fetch")
index 447aa023e6e382d69164526b4726f8913b49cace..56ab283f4d6b8599c5bf10aea8e6e47e24dd86e2 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("generate-lockfile")
index 90719066e4188c86961818959ffe769d9666e63e..4bbcba13326951ecba3b6493a7c49f34aa9e3891 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("git-checkout")
index a7038e0e0ae5bd5ba5de022be4fc557b920aa2c4..e9d618b43743fb29e106253dfbc8fa7e29760e71 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("init")
index 237e819ca4c47c994f30348522ec01ad45edee17..ce1834d9d4f6db625b23efee4630e489cfd7f85e 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("install")
index ef18d30a6247de6ddd06f0dd341f0227cd3e292b..1bddac4c25cbd2a1fd01d766c59cbc0265b26e88 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("locate-project")
index c5d77b37338400e113560dd601ca0175bf17b788..045770181933019d9118b3454fe52ae28c9292c1 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("login")
index 7b407a9f2ba040f366dc33937d340fa06c1fe77c..7f4904c1441762644025140fe4ebcb90936392d4 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("metadata")
index 78cf341841ce8f11476d1c435ca3dcf0130e9708..8fb63d35fa09fac79716f436264eac203273024c 100644 (file)
@@ -17,12 +17,13 @@ use cargo::util::{ToUrl, CargoResultExt};
 use cargo::ops::{self, CompileMode, OutputMetadataOptions};
 use cargo::sources::{GitSource, RegistrySource};
 
-use self::command_prelude::*;
 use std::collections::BTreeSet;
 use std::env;
 use std::fs;
+
 use search_directories;
 use is_executable;
+use command_prelude::*;
 
 pub fn do_main(config: &mut Config) -> CliResult {
     let args = cli().get_matches_safe()?;
@@ -727,329 +728,3 @@ mod update;
 mod verify_project;
 mod version;
 mod yank;
-
-mod command_prelude {
-    use std::path::PathBuf;
-
-    use clap::{self, SubCommand, AppSettings, ArgMatches};
-    use cargo::{Config, CargoResult};
-    use cargo::core::Workspace;
-    use cargo::ops::{CompileMode, CompileOptions, CompileFilter, Packages, MessageFormat,
-                     VersionControl, NewOptions};
-    use cargo::util::important_paths::find_root_manifest_for_wd;
-
-    pub use clap::Arg;
-
-    pub type App = clap::App<'static, 'static>;
-
-    pub trait CommonArgs: Sized {
-        fn _arg(self, arg: Arg<'static, 'static>) -> Self;
-
-        fn arg_package(self, package: &'static str, all: &'static str, exclude: &'static str) -> Self {
-            self._arg(opt("package", package).short("p").value_name("SPEC").multiple(true))
-                ._arg(opt("all", all))
-                ._arg(opt("exclude", exclude).value_name("SPEC").multiple(true))
-        }
-
-        fn arg_single_package(self, package: &'static str) -> Self {
-            self._arg(opt("package", package).short("p").value_name("SPEC"))
-        }
-
-        fn arg_jobs(self) -> Self {
-            self._arg(
-                opt("jobs", "Number of parallel jobs, defaults to # of CPUs")
-                    .short("j").value_name("N")
-            )
-        }
-
-        fn arg_targets_all(
-            self,
-            lib: &'static str,
-            bin: &'static str,
-            bins: &'static str,
-            examle: &'static str,
-            examles: &'static str,
-            test: &'static str,
-            tests: &'static str,
-            bench: &'static str,
-            benchs: &'static str,
-            all: &'static str,
-        ) -> Self {
-            self.arg_targets_lib_bin(lib, bin, bins)
-                ._arg(opt("example", examle).value_name("NAME").multiple(true))
-                ._arg(opt("examples", examles))
-                ._arg(opt("test", test).value_name("NAME").multiple(true))
-                ._arg(opt("tests", tests))
-                ._arg(opt("bench", bench).value_name("NAME").multiple(true))
-                ._arg(opt("benches", benchs))
-                ._arg(opt("all-targets", all))
-        }
-
-        fn arg_targets_lib_bin(
-            self,
-            lib: &'static str,
-            bin: &'static str,
-            bins: &'static str,
-        ) -> Self {
-            self._arg(opt("lib", lib))
-                ._arg(opt("bin", bin).value_name("NAME").multiple(true))
-                ._arg(opt("bins", bins))
-        }
-
-        fn arg_targets_bins_examples(
-            self,
-            bin: &'static str,
-            bins: &'static str,
-            example: &'static str,
-            examples: &'static str,
-        ) -> Self {
-            self._arg(opt("bin", bin).value_name("NAME").multiple(true))
-                ._arg(opt("bins", bins))
-                ._arg(opt("example", example).value_name("NAME").multiple(true))
-                ._arg(opt("examples", examples))
-        }
-
-        fn arg_targets_bin_example(
-            self,
-            bin: &'static str,
-            example: &'static str,
-        ) -> Self {
-            self._arg(opt("bin", bin).value_name("NAME").multiple(true))
-                ._arg(opt("example", example).value_name("NAME").multiple(true))
-        }
-
-        fn arg_features(self) -> Self {
-            self
-                ._arg(
-                    opt("features", "Space-separated list of features to activate")
-                        .value_name("FEATURES")
-                )
-                ._arg(opt("all-features", "Activate all available features"))
-                ._arg(opt("no-default-features", "Do not activate the `default` feature"))
-        }
-
-        fn arg_release(self, release: &'static str) -> Self {
-            self._arg(opt("release", release))
-        }
-
-        fn arg_target_triple(self, target: &'static str) -> Self {
-            self._arg(opt("target", target).value_name("TRIPLE"))
-        }
-
-        fn arg_manifest_path(self) -> Self {
-            self._arg(opt("manifest-path", "Path to Cargo.toml").value_name("PATH"))
-        }
-
-        fn arg_message_format(self) -> Self {
-            self._arg(
-                opt("message-format", "Error format")
-                    .value_name("FMT")
-                    .case_insensitive(true)
-                    .possible_values(&["human", "json"]).default_value("human")
-            )
-        }
-
-        fn arg_new_opts(self) -> Self {
-            self._arg(
-                opt("vcs", "\
-Initialize a new repository for the given version \
-control system (git, hg, pijul, or fossil) or do not \
-initialize any version control at all (none), overriding \
-a global configuration.")
-                    .value_name("VCS")
-                    .possible_values(&["git", "hg", "pijul", "fossil", "none"])
-            )
-                ._arg(opt("bin", "Use a binary (application) template [default]"))
-                ._arg(opt("lib", "Use a library template"))
-                ._arg(
-                    opt("name", "Set the resulting package name, defaults to the directory name")
-                        .value_name("NAME")
-                )
-        }
-
-        fn arg_index(self) -> Self {
-            self
-                ._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)
-                )
-        }
-    }
-
-    impl CommonArgs for App {
-        fn _arg(self, arg: Arg<'static, 'static>) -> Self {
-            self.arg(arg)
-        }
-    }
-
-    pub fn opt(name: &'static str, help: &'static str) -> Arg<'static, 'static> {
-        Arg::with_name(name).long(name).help(help)
-    }
-
-    pub fn subcommand(name: &'static str) -> App {
-        SubCommand::with_name(name)
-            .settings(&[
-                AppSettings::UnifiedHelpMessage,
-                AppSettings::DeriveDisplayOrder,
-                AppSettings::DontCollapseArgsInUsage,
-            ])
-    }
-
-    pub fn values(args: &ArgMatches, name: &str) -> Vec<String> {
-        args.values_of(name).unwrap_or_default()
-            .map(|s| s.to_string())
-            .collect()
-    }
-
-
-    pub fn config_from_args(config: &mut Config, args: &ArgMatches) -> CargoResult<()> {
-        let color = args.value_of("color").map(|s| s.to_string());
-        config.configure(
-            args.occurrences_of("verbose") as u32,
-            if args.is_present("quite") { Some(true) } else { None },
-            &color,
-            args.is_present("frozen"),
-            args.is_present("locked"),
-            &args.values_of_lossy("unstable-features").unwrap_or_default(),
-        )
-    }
-
-    pub fn root_manifest_from_args(config: &Config, args: &ArgMatches) -> CargoResult<PathBuf> {
-        let manifest_path = args.value_of("manifest-path").map(|s| s.to_string());
-        find_root_manifest_for_wd(manifest_path, config.cwd())
-    }
-
-    pub fn workspace_from_args<'a>(config: &'a Config, args: &ArgMatches) -> CargoResult<Workspace<'a>> {
-        let root = root_manifest_from_args(config, args)?;
-        Workspace::new(&root, config)
-    }
-
-    pub fn jobs_from_args(args: &ArgMatches) -> CargoResult<Option<u32>> { //FIXME: validation
-        let jobs = match args.value_of("jobs") {
-            None => None,
-            Some(jobs) => Some(jobs.parse::<u32>().map_err(|_| {
-                clap::Error::value_validation_auto(
-                    format!("could not parse `{}` as a number", jobs)
-                )
-            })?)
-        };
-        Ok(jobs)
-    }
-
-    pub fn compile_options_from_args<'a>(
-        config: &'a Config,
-        args: &'a ArgMatches<'a>,
-        mode: CompileMode,
-    ) -> CargoResult<CompileOptions<'a>> {
-        let spec = Packages::from_flags(
-            args.is_present("all"),
-            values(args, "exclude"),
-            values(args, "package"),
-        )?;
-
-        let message_format = match args.value_of("message-format") {
-            None => MessageFormat::Human,
-            Some(f) => {
-                if f.eq_ignore_ascii_case("json") {
-                    MessageFormat::Json
-                } else if f.eq_ignore_ascii_case("human") {
-                    MessageFormat::Human
-                } else {
-                    panic!("Impossible message format: {:?}", f)
-                }
-            }
-        };
-
-        let opts = CompileOptions {
-            config,
-            jobs: jobs_from_args(args)?,
-            target: args.value_of("target"),
-            features: values(args, "features"),
-            all_features: args.is_present("all-features"),
-            no_default_features: args.is_present("no-default-features"),
-            spec,
-            mode,
-            release: args.is_present("release"),
-            filter: CompileFilter::new(args.is_present("lib"),
-                                       values(args, "bin"), args.is_present("bins"),
-                                       values(args, "test"), args.is_present("tests"),
-                                       values(args, "example"), args.is_present("examples"),
-                                       values(args, "bench"), args.is_present("benches"),
-                                       args.is_present("all-targets")),
-            message_format,
-            target_rustdoc_args: None,
-            target_rustc_args: None,
-        };
-        Ok(opts)
-    }
-
-    pub fn compile_options_from_args_for_single_package<'a>(
-        config: &'a Config,
-        args: &'a ArgMatches<'a>,
-        mode: CompileMode,
-    ) -> CargoResult<CompileOptions<'a>> {
-        let mut compile_opts = compile_options_from_args(config, args, mode)?;
-        compile_opts.spec = Packages::Packages(values(args, "package"));
-        Ok(compile_opts)
-    }
-
-    pub fn new_opts_from_args<'a>(args: &'a ArgMatches<'a>, path: &'a str) -> CargoResult<NewOptions<'a>> {
-        let vcs = args.value_of("vcs").map(|vcs| match vcs {
-            "git" => VersionControl::Git,
-            "hg" => VersionControl::Hg,
-            "pijul" => VersionControl::Pijul,
-            "fossil" => VersionControl::Fossil,
-            "none" => VersionControl::NoVcs,
-            vcs => panic!("Impossible vcs: {:?}", vcs),
-        });
-        NewOptions::new(vcs,
-                        args.is_present("bin"),
-                        args.is_present("lib"),
-                        path,
-                        args.value_of("name"))
-    }
-
-    pub fn registry_from_args(config: &Config, args: &ArgMatches) -> CargoResult<Option<String>> {
-        match args.value_of("registry") {
-            Some(registry) => {
-                if !config.cli_unstable().unstable_options {
-                    return Err(format_err!("registry option is an unstable feature and \
-                                requires -Zunstable-options to use.").into());
-                }
-                Ok(Some(registry.to_string()))
-            }
-            None => Ok(None),
-        }
-    }
-
-    pub fn index_from_args(config: &Config, args: &ArgMatches) -> CargoResult<Option<String>> {
-        // 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. 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())
-        };
-        Ok(index)
-    }
-}
index f912c958180ab188ff932ac9c80c4ee0f29c2fd0..eb03e37d564eafc98b1da9ece8e32659b807a0d9 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("new")
index 4f1b87003ed1798c07bfabe6521f41009c36809b..dd7c5adf1aa791457eda4842e5a9f5506cef3b26 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("owner")
index e8215c77c2099a03639ad0bac5c45dfe22310fb5..59ba384b7e1e53682c655cc8c87074bba4971568 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("package")
index 764a5cb4b02018d00285b6282b712c82127fb74a..26335735aa43be8cea1b6007001a6b74509ed15e 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("pkgid")
index 0b0d08546a1c23d6f943946fb5406e7f4a2995ce..fc4ead218db6fdc6ca795529e68764be0d702961 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("publish")
index c13e7e180e0bc180878a54148edbd67235aeb49a..ec6ffec836c81aac4ef9f9331bc3406bac257f59 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("read-manifest")
index 85ad63dbd1cc816f57c4efa079cc6b9b04ad063a..dae6c9de26f9b00a93a1219459b5cd68633bed38 100644 (file)
@@ -1,6 +1,6 @@
 use clap::AppSettings;
 
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("run").alias("r")
index bdc5aa1851936df3c6397b535fda21885c2fdf89..8074a551e44336e28a16c11dade28901b155cf6d 100644 (file)
@@ -1,6 +1,6 @@
 use clap::AppSettings;
 
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("rustc")
index 9f8d164bf14b4c932e15748933696c842f5d5637..5db6ca9dd73efaa661e461fb52fe96c51f7bf0ff 100644 (file)
@@ -1,6 +1,6 @@
 use clap::AppSettings;
 
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("rustdoc")
index 9e9f727f1e968ddcdc74244fb41f618bafcb83ee..62d023b0fbe7665cbc59c4c353e1a02ccc1956bc 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("search")
index d4ae77fa9bcab09e1eaff3ca65bf40608d837031..9c0ae57b7b4f86b4e51aa4c61c6e43f6f699a527 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 use clap::AppSettings;
 
 pub fn cli() -> App {
index 0ad50d3f51a860c2226b6b61657145c2bda284c6..5ab7513e5a7b63dc3394f24776d1489956f748d5 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("uninstall")
index 2b2e82ed510d5f92c80df149a2317e3a9837281e..523051c2576f54f1bac569f8cc5b1a5c0e326f93 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("update")
index 890de1154d430121dfd40a6bd44c3b67da6f3131..926d8014cc1f87ba22124da5c875938f695daf1a 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("verify-project")
index 75c2a9f06ffe2e7f5ddb4923db7892f9bd0484c9..0d7de9a6cde005eb6d23056b3eb8af36210f2295 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("version")
index 41a418554d7fd8525524716e2337b30705dfa429..54039a3b1b5bd5fd565172f833858d8d7ff80d64 100644 (file)
@@ -1,4 +1,4 @@
-use super::command_prelude::*;
+use command_prelude::*;
 
 pub fn cli() -> App {
     subcommand("yank")