-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
login.rs
42 lines (38 loc) · 1.17 KB
/
login.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
use cargo::ops;
use cargo::ops::RegistryOrIndex;
use crate::command_prelude::*;
pub fn cli() -> Command {
subcommand("login")
.about("Log in to a registry.")
.arg(Arg::new("token").value_name("TOKEN").action(ArgAction::Set))
.arg_registry("Registry to use")
.arg(
Arg::new("args")
.help("Additional arguments for the credential provider")
.num_args(0..)
.last(true),
)
.arg_silent_suggestion()
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help login</>` for more detailed information.\n"
))
}
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let reg = args.registry_or_index(gctx)?;
assert!(
!matches!(reg, Some(RegistryOrIndex::Index(..))),
"must not be index URL"
);
let extra_args = args
.get_many::<String>("args")
.unwrap_or_default()
.map(String::as_str)
.collect::<Vec<_>>();
ops::registry_login(
gctx,
args.get_one::<String>("token").map(|s| s.as_str().into()),
reg.as_ref(),
&extra_args,
)?;
Ok(())
}