MCPcopy Create free account
hub / github.com/BigBoot/AutoKuma / from

Method from

kuma-cli/src/cli.rs:77–114  ·  view source on GitHub ↗
(value: Cli)

Source from the content-addressed store, hash-verified

75
76impl From<Cli> for Config {
77 fn from(value: Cli) -> Self {
78 config::Config::builder()
79 .add_source(File::from_str(
80 &serde_json::to_string(&json!({"tls": {}})).unwrap(),
81 FileFormat::Json,
82 ))
83 .add_source(config::File::with_name(&dirs::config_local_dir().map(|dir| dir.join("kuma").join("config").to_string_lossy().to_string()).unwrap_or_default()).required(false))
84 .add_source(config::File::with_name("kuma").required(false))
85 .add_source(
86 config::Environment::with_prefix("KUMA")
87 .separator("__")
88 .prefix_separator("__"),
89 )
90 .set_default("headers", Vec::<String>::new()).unwrap()
91 .set_override_option("url", value.url.clone()).unwrap()
92 .set_override_option("username", value.username.clone()).unwrap()
93 .set_override_option("password", value.password.clone()).unwrap()
94 .set_override_option("mfa_token", value.mfa_token.clone()).unwrap()
95 .set_override_option("mfa_secret", value.mfa_secret.clone()).unwrap()
96 .set_override_option("auth_token", value.auth_token.clone()).unwrap()
97 .set_override_option(
98 "headers",
99 match value.headers.is_empty() {
100 true => None,
101 false => Some(value.headers.clone()),
102 },
103 ).unwrap()
104 .set_override_option("connect_timeout", value.connect_timeout).unwrap()
105 .set_override_option("call_timeout", value.call_timeout).unwrap()
106 .set_override_option("tls.verify", value.tls_no_verify.map(|v| !v)).unwrap()
107 .set_override_option("tls.cert", value.tls_certificate.clone()).unwrap()
108 .build()
109 .and_then(|config| config.try_deserialize())
110 .unwrap_or_else(|e| match &e {
111 config::ConfigError::Message(msg) if msg == "missing field `url`" => Cli::command().error(clap::error::ErrorKind::MissingRequiredArgument, "the following required arguments were not provided:\n \x1b[32m--url <URL>\x1b[0m").exit(),
112 e => Err(e).unwrap_or_die(&value),
113 })
114 }
115}
116
117#[derive(Subcommand, Clone, Debug)]

Callers

nothing calls this directly

Calls 1

unwrap_or_dieMethod · 0.45

Tested by

no test coverage detected