1
- use cargo:: ops;
2
- use cargo:: util:: { CliResult , CliError , Config } ;
3
1
use std:: path:: Path ;
4
2
5
- #[ allow( dead_code) ] // for now until all options are implemented
3
+ use cargo:: ops;
4
+ use cargo:: core:: { SourceId , GitReference } ;
5
+ use cargo:: util:: { CliResult , Config , ToUrl , human} ;
6
6
7
7
#[ derive( RustcDecodable ) ]
8
8
struct Options {
9
9
flag_jobs : Option < u32 > ,
10
10
flag_features : Vec < String > ,
11
11
flag_no_default_features : bool ,
12
12
flag_debug : bool ,
13
- flag_bin : Option < String > ,
13
+ flag_bin : Vec < String > ,
14
14
flag_example : Vec < String > ,
15
- flag_package : Vec < String > ,
16
15
flag_verbose : bool ,
16
+ flag_quiet : bool ,
17
+ flag_color : Option < String > ,
17
18
flag_root : Option < String > ,
19
+ flag_list : bool ,
20
+
21
+ arg_crate : Option < String > ,
22
+ flag_vers : Option < String > ,
23
+
24
+ flag_git : Option < String > ,
25
+ flag_branch : Option < String > ,
26
+ flag_tag : Option < String > ,
27
+ flag_rev : Option < String > ,
28
+
29
+ flag_path : Option < String > ,
18
30
}
19
31
20
32
pub const USAGE : & ' static str = "
21
- Install a crate onto the local system
33
+ Install a Rust binary
22
34
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:
35
+ Usage:
36
+ cargo install [options] [<crate>]
30
37
cargo install [options] --list
31
38
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
39
+ Specifying what crate to install:
40
+ --vers VERS Specify a version to install from crates.io
41
+ --git URL Git URL to install the specified crate from
42
+ --branch BRANCH Branch to use when installing from git
43
+ --tag TAG Tag to use when installing from git
44
+ --rev SHA Specific commit to use when installing from git
45
+ --path PATH Filesystem path to local crate to install
46
+
47
+ Build and install options:
48
+ -h, --help Print this message
49
+ -j N, --jobs N The number of jobs to run in parallel
50
+ --features FEATURES Space-separated list of features to activate
51
+ --no-default-features Do not build the `default` feature
52
+ --debug Build in debug mode instead of release mode
53
+ --bin NAME Only install the binary NAME
54
+ --example EXAMPLE Install the example EXAMPLE instead of binaries
55
+ --root DIR Directory to install packages into
56
+ -v, --verbose Use verbose output
57
+ -q, --quiet Less output printed to stdout
58
+ --color WHEN Coloring: auto, always, never
44
59
45
60
This command manages Cargo's local set of install binary crates. Only packages
46
61
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).
62
+ the installation root's `bin` folder. The installation root is determined, in
63
+ order of precedence, by `--root`, `$CARGO_INSTALL_ROOT`, the `install.root`
64
+ configuration key, and finally the home directory (which is either
65
+ `$CARGO_HOME` if set or `$HOME/.cargo` by default).
49
66
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 .
67
+ There are multiple sources from which a crate can be installed . The default
68
+ location is crates.io but the `--git` and `--path` flags can change this source.
69
+ If the source contains more than one package (such as crates.io or a git
70
+ repository with multiple crates) the `<crate>` argument is required to indicate
71
+ which crate should be installed .
55
72
56
73
Crates from crates.io can optionally specify the version they wish to install
57
74
via the `--vers` flags, and similarly packages from git repositories can
@@ -64,26 +81,50 @@ The `--list` option will list all installed packages (and their versions).
64
81
" ;
65
82
66
83
pub fn execute ( options : Options , config : & Config ) -> CliResult < Option < ( ) > > {
67
- config. shell ( ) . set_verbose ( options. flag_verbose ) ;
84
+ try!( config. shell ( ) . set_verbosity ( options. flag_verbose , options. flag_quiet ) ) ;
85
+ try!( config. shell ( ) . set_color_config ( options. flag_color . as_ref ( ) . map ( |s| & s[ ..] ) ) ) ;
68
86
69
87
let compile_opts = ops:: CompileOptions {
70
88
config : config,
71
89
jobs : options. flag_jobs ,
72
90
target : None ,
73
91
features : & options. flag_features ,
74
92
no_default_features : options. flag_no_default_features ,
75
- spec : None ,
93
+ spec : & [ ] ,
76
94
exec_engine : None ,
77
95
mode : ops:: CompileMode :: Build ,
78
- release : true ,
79
- filter : ops:: CompileFilter :: Everything ,
96
+ release : !options. flag_debug ,
97
+ filter : ops:: CompileFilter :: new ( false , & options. flag_bin , & [ ] ,
98
+ & options. flag_example , & [ ] ) ,
80
99
target_rustc_args : None ,
81
100
} ;
82
101
83
- let root = & Path :: new ( "$HOME/.cargo/bin" ) ;
102
+ let source = if let Some ( url) = options. flag_git {
103
+ let url = try!( url. to_url ( ) . map_err ( human) ) ;
104
+ let gitref = if let Some ( branch) = options. flag_branch {
105
+ GitReference :: Branch ( branch)
106
+ } else if let Some ( tag) = options. flag_tag {
107
+ GitReference :: Tag ( tag)
108
+ } else if let Some ( rev) = options. flag_rev {
109
+ GitReference :: Rev ( rev)
110
+ } else {
111
+ GitReference :: Branch ( "master" . to_string ( ) )
112
+ } ;
113
+ SourceId :: for_git ( & url, gitref)
114
+ } else if let Some ( path) = options. flag_path {
115
+ try!( SourceId :: for_path ( Path :: new ( & path) ) )
116
+ } else {
117
+ try!( SourceId :: for_central ( config) )
118
+ } ;
119
+
120
+ let krate = options. arg_crate . as_ref ( ) . map ( |s| & s[ ..] ) ;
121
+ let vers = options. flag_vers . as_ref ( ) . map ( |s| & s[ ..] ) ;
122
+ let root = options. flag_root . as_ref ( ) . map ( |s| & s[ ..] ) ;
84
123
85
- ops:: install ( & root,
86
- & compile_opts) . map_err ( |err| {
87
- CliError :: from_boxed ( err, 101 )
88
- } ) . map ( |_| None )
124
+ if options. flag_list {
125
+ try!( ops:: install_list ( root, config) ) ;
126
+ } else {
127
+ try!( ops:: install ( root, krate, & source, vers, & compile_opts) ) ;
128
+ }
129
+ Ok ( None )
89
130
}
0 commit comments