|
| 1 | +use cargo::ops; |
| 2 | +use cargo::util::{CliResult, CliError, Config}; |
| 3 | +use std::path::Path; |
| 4 | + |
| 5 | +#[allow(dead_code)] // for now until all options are implemented |
| 6 | + |
| 7 | +#[derive(RustcDecodable)] |
| 8 | +struct Options { |
| 9 | + flag_jobs: Option<u32>, |
| 10 | + flag_features: Vec<String>, |
| 11 | + flag_no_default_features: bool, |
| 12 | + flag_debug: bool, |
| 13 | + flag_bin: Option<String>, |
| 14 | + flag_example: Vec<String>, |
| 15 | + flag_package: Vec<String>, |
| 16 | + flag_verbose: bool, |
| 17 | + flag_root: Option<String>, |
| 18 | +} |
| 19 | + |
| 20 | +pub const USAGE: &'static str = " |
| 21 | +Install a crate onto the local system |
| 22 | +
|
| 23 | +Installing new crates: |
| 24 | + cargo install [options] |
| 25 | + cargo install [options] [-p CRATE | --package CRATE] [--vers VERS] |
| 26 | + cargo install [options] --git URL [--branch BRANCH | --tag TAG | --rev SHA] |
| 27 | + cargo install [options] --path PATH |
| 28 | +
|
| 29 | +Managing installed crates: |
| 30 | + cargo install [options] --list |
| 31 | +
|
| 32 | +Options: |
| 33 | + -h, --help Print this message |
| 34 | + -j N, --jobs N The number of jobs to run in parallel |
| 35 | + --features FEATURES Space-separated list of features to activate |
| 36 | + --no-default-features Do not build the `default` feature |
| 37 | + --debug Build in debug mode instead of release mode |
| 38 | + --bin NAME Only install the binary NAME |
| 39 | + --example EXAMPLE Install the example EXAMPLE instead of binaries |
| 40 | + -p, --package CRATE Install this crate from crates.io or select the |
| 41 | + package in a repository/path to install. |
| 42 | + -v, --verbose Use verbose output |
| 43 | + --root DIR Directory to install packages into |
| 44 | +
|
| 45 | +This command manages Cargo's local set of install binary crates. Only packages |
| 46 | +which have [[bin]] targets can be installed, and all binaries are installed into |
| 47 | +`$HOME/.cargo/bin` by default (or `$CARGO_HOME/bin` if you change the home |
| 48 | +directory). |
| 49 | +
|
| 50 | +There are multiple methods of installing a new crate onto the system. The |
| 51 | +`cargo install` command with no arguments will install the current crate (as |
| 52 | +specifed by the current directory). Otherwise the `-p`, `--package`, `--git`, |
| 53 | +and `--path` options all specify the source from which a crate is being |
| 54 | +installed. The `-p` and `--package` options will download crates from crates.io. |
| 55 | +
|
| 56 | +Crates from crates.io can optionally specify the version they wish to install |
| 57 | +via the `--vers` flags, and similarly packages from git repositories can |
| 58 | +optionally specify the branch, tag, or revision that should be installed. If a |
| 59 | +crate has multiple binaries, the `--bin` argument can selectively install only |
| 60 | +one of them, and if you'd rather install examples the `--example` argument can |
| 61 | +be used as well. |
| 62 | +
|
| 63 | +The `--list` option will list all installed packages (and their versions). |
| 64 | +"; |
| 65 | + |
| 66 | +pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> { |
| 67 | + config.shell().set_verbose(options.flag_verbose); |
| 68 | + |
| 69 | + let compile_opts = ops::CompileOptions { |
| 70 | + config: config, |
| 71 | + jobs: options.flag_jobs, |
| 72 | + target: None, |
| 73 | + features: &options.flag_features, |
| 74 | + no_default_features: options.flag_no_default_features, |
| 75 | + spec: None, |
| 76 | + exec_engine: None, |
| 77 | + mode: ops::CompileMode::Build, |
| 78 | + release: true, |
| 79 | + filter: ops::CompileFilter::Everything, |
| 80 | + target_rustc_args: None, |
| 81 | + }; |
| 82 | + |
| 83 | + let root = &Path::new("$HOME/.cargo/bin"); |
| 84 | + |
| 85 | + ops::install(&root, |
| 86 | + &compile_opts).map_err(|err| { |
| 87 | + CliError::from_boxed(err, 101) |
| 88 | + }).map(|_| None) |
| 89 | +} |
0 commit comments