-
Notifications
You must be signed in to change notification settings - Fork 917
/
Copy pathsetup_mode.rs
131 lines (109 loc) · 3.52 KB
/
setup_mode.rs
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
use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
use tracing::warn;
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
use crate::{
cli::{
common::{self, update_console_filter},
self_update::{self, InstallOpts},
},
dist::Profile,
process::Process,
toolchain::MaybeOfficialToolchainName,
utils,
};
/// The installer for rustup
#[derive(Debug, Parser)]
#[command(
name = "rustup-init",
bin_name = "rustup-init[EXE]",
version = common::version(),
before_help = format!("rustup-init {}", common::version()),
)]
struct RustupInit {
/// Set log level to 'DEBUG' if 'RUSTUP_LOG' is unset
#[arg(short, long, conflicts_with = "quiet")]
verbose: bool,
/// Disable progress output, set log level to 'WARN' if 'RUSTUP_LOG' is unset
#[arg(short, long, conflicts_with = "verbose")]
quiet: bool,
/// Disable confirmation prompt
#[arg(short = 'y')]
no_prompt: bool,
/// Choose a default host triple
#[arg(long)]
default_host: Option<String>,
/// Choose a default toolchain to install. Use 'none' to not install any toolchains at all
#[arg(long)]
default_toolchain: Option<MaybeOfficialToolchainName>,
#[arg(long, value_enum, default_value_t)]
profile: Profile,
/// Comma-separated list of component names to also install
#[arg(short, long, value_delimiter = ',')]
component: Vec<String>,
/// Comma-separated list of target names to also install
#[arg(short, long, value_delimiter = ',')]
target: Vec<String>,
/// Don't update any existing default toolchain after install
#[arg(long)]
no_update_default_toolchain: bool,
/// Don't configure the PATH environment variable
#[arg(long)]
no_modify_path: bool,
/// Secret command used during self-update. Not for users
#[arg(long, hide = true)]
self_replace: bool,
/// Internal testament dump used during CI. Not for users
#[arg(long, hide = true)]
dump_testament: bool,
}
#[tracing::instrument(level = "trace")]
pub async fn main(
current_dir: PathBuf,
process: &Process,
console_filter: Handle<EnvFilter, Registry>,
) -> Result<utils::ExitCode> {
use clap::error::ErrorKind;
let RustupInit {
verbose,
quiet,
no_prompt,
default_host,
default_toolchain,
profile,
component,
target,
no_update_default_toolchain,
no_modify_path,
self_replace,
dump_testament,
} = match RustupInit::try_parse() {
Ok(args) => args,
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()),
};
if self_replace {
return self_update::self_replace(process);
}
if dump_testament {
return common::dump_testament(process);
}
if profile == Profile::Complete {
warn!("{}", common::WARN_COMPLETE_PROFILE);
}
update_console_filter(process, &console_filter, quiet, verbose);
let opts = InstallOpts {
default_host_triple: default_host,
default_toolchain,
profile,
no_modify_path,
no_update_toolchain: no_update_default_toolchain,
components: &component.iter().map(|s| &**s).collect::<Vec<_>>(),
targets: &target.iter().map(|s| &**s).collect::<Vec<_>>(),
};
self_update::install(current_dir, no_prompt, quiet, opts, process).await
}