-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmain.rs
More file actions
89 lines (81 loc) · 3.2 KB
/
Copy pathmain.rs
File metadata and controls
89 lines (81 loc) · 3.2 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
mod actions_catalog;
mod api_explorer;
mod application;
mod auth;
mod config;
mod domain;
mod env;
mod environments;
mod extension;
mod webhook;
use std::{process::ExitCode, sync::Arc};
use clap::Arg;
use cli_engine::{BuildInfo, Cli, CliConfig, NextAction};
use tracing_subscriber::filter::LevelFilter;
use crate::env::get_env;
#[tokio::main]
async fn main() -> ExitCode {
let trace_filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(LevelFilter::WARN.into())
.from_env_lossy()
.add_directive(
"cli_engine::auth::pkce=info"
.parse()
.expect("valid cli-engine PKCE tracing directive"),
);
tracing_subscriber::fmt()
.with_env_filter(trace_filter)
.with_writer(std::io::stderr)
.without_time()
.with_target(false)
.with_level(false)
.init();
let auth_provider = Arc::new(auth::CompositeAuthProvider::new());
let cli = Cli::new(
CliConfig::new("gddy", "GoDaddy developer CLI", "gddy")
.with_build(BuildInfo::new(env!("CARGO_PKG_VERSION")))
.with_default_auth_provider("godaddy")
.with_auth_provider(auth_provider)
.with_register_flags(Arc::new(|cmd| {
cmd.arg(
Arg::new("env")
.long("env")
.global(true)
.value_name("ENV")
.default_value(
get_env().unwrap_or_else(|| environments::DEFAULT_ENV.to_owned()),
)
.help("Target environment (ote|prod)"),
)
}))
.with_apply_flags(Arc::new(|matches, mw| {
if let Some(env) = matches.get_one::<String>("env") {
// Validate only an explicitly-provided `--env`. The default
// value comes from `.gdenv`/DEFAULT_ENV (already filtered), so
// validating it unconditionally would let a malformed local
// config fail *every* command — even ones not using `--env`.
if matches.value_source("env") == Some(clap::parser::ValueSource::CommandLine) {
environments::resolve(env)
.map_err(|e| cli_engine::CliCoreError::message(e.to_string()))?;
}
mw.env = env.clone();
}
Ok(())
}))
.with_root_next_actions(Arc::new(|| {
vec![
NextAction::new("auth status", "Check authentication status"),
NextAction::new("env get", "Get the current active environment"),
NextAction::new("application list", "List all applications"),
NextAction::new("tree", "Display the full command tree"),
]
}))
.with_module(actions_catalog::module())
.with_module(api_explorer::module())
.with_module(application::module())
.with_module(domain::module())
.with_module(env::module())
.with_module(webhook::module()),
);
cli.execute().await
}