forked from rust-lang/rustup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_mode.rs
More file actions
158 lines (146 loc) · 5.24 KB
/
setup_mode.rs
File metadata and controls
158 lines (146 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
use anyhow::Result;
use clap::{builder::PossibleValuesParser, value_parser, Arg, ArgAction, Command};
use crate::{
cli::{
common,
self_update::{self, InstallOpts},
},
currentprocess::{argsource::ArgSource, filesource::StdoutSource},
dist::dist::Profile,
process,
toolchain::names::MaybeOfficialToolchainName,
utils::utils,
};
#[cfg_attr(feature = "otel", tracing::instrument)]
pub fn main() -> Result<utils::ExitCode> {
use clap::error::ErrorKind;
let args: Vec<_> = process().args().collect();
let arg1 = args.get(1).map(|a| &**a);
// Secret command used during self-update. Not for users.
if arg1 == Some("--self-replace") {
return self_update::self_replace();
}
// Internal testament dump used during CI. Not for users.
if arg1 == Some("--dump-testament") {
common::dump_testament()?;
return Ok(utils::ExitCode(0));
}
// NOTICE: If you change anything here, please make the same changes in rustup-init.sh
let cli = Command::new("rustup-init")
.version(common::version())
.before_help(format!("rustup-init {}", common::version()))
.about("The installer for rustup")
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.help("Enable verbose output")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("quiet")
.conflicts_with("verbose")
.short('q')
.long("quiet")
.help("Disable progress output")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("no-prompt")
.short('y')
.help("Disable confirmation prompt.")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("default-host")
.long("default-host")
.num_args(1)
.help("Choose a default host triple"),
)
.arg(
Arg::new("default-toolchain")
.long("default-toolchain")
.num_args(1)
.help("Choose a default toolchain to install. Use 'none' to not install any toolchains at all")
.value_parser(value_parser!(MaybeOfficialToolchainName))
)
.arg(
Arg::new("profile")
.long("profile")
.value_parser(PossibleValuesParser::new(Profile::names()))
.default_value(Profile::default_name()),
)
.arg(
Arg::new("components")
.help("Component name to also install")
.long("component")
.short('c')
.num_args(1..)
.use_value_delimiter(true)
.action(ArgAction::Append),
)
.arg(
Arg::new("targets")
.help("Target name to also install")
.long("target")
.short('t')
.num_args(1..)
.use_value_delimiter(true)
.action(ArgAction::Append),
)
.arg(
Arg::new("no-update-default-toolchain")
.long("no-update-default-toolchain")
.help("Don't update any existing default toolchain after install")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("no-modify-path")
.long("no-modify-path")
.help("Don't configure the PATH environment variable")
.action(ArgAction::SetTrue),
);
let matches = match cli.try_get_matches_from(process().args_os()) {
Ok(matches) => matches,
Err(e) if [ErrorKind::DisplayHelp, ErrorKind::DisplayVersion].contains(&e.kind()) => {
write!(process().stdout().lock(), "{e}")?;
return Ok(utils::ExitCode(0));
}
Err(e) => return Err(e.into()),
};
let no_prompt = matches.get_flag("no-prompt");
let verbose = matches.get_flag("verbose");
let quiet = matches.get_flag("quiet");
let default_host = matches
.get_one::<String>("default-host")
.map(ToOwned::to_owned);
let default_toolchain = matches
.get_one::<MaybeOfficialToolchainName>("default-toolchain")
.map(ToOwned::to_owned);
let profile = matches
.get_one::<String>("profile")
.expect("Unreachable: Clap should supply a default");
let no_modify_path = matches.get_flag("no-modify-path");
let no_update_toolchain = matches.get_flag("no-update-default-toolchain");
let components: Vec<_> = matches
.get_many::<String>("components")
.map(|v| v.map(|s| &**s).collect())
.unwrap_or_else(Vec::new);
let targets: Vec<_> = matches
.get_many::<String>("targets")
.map(|v| v.map(|s| &**s).collect())
.unwrap_or_else(Vec::new);
let opts = InstallOpts {
default_host_triple: default_host,
default_toolchain,
profile: profile.to_owned(),
no_modify_path,
no_update_toolchain,
components: &components,
targets: &targets,
};
if profile == "complete" {
warn!("{}", common::WARN_COMPLETE_PROFILE);
}
self_update::install(no_prompt, verbose, quiet, opts)
}