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
pub mod auth;
mod completions;
pub mod containers;
pub mod deploy;
mod domains;
mod gateways;
pub mod ignite;
mod link;
pub mod projects;
mod secrets;
pub mod update;
mod whoami;
use anyhow::Result;
use clap::Subcommand;
use crate::state::State;
#[derive(Debug, Subcommand)]
pub enum Commands {
Auth(auth::Options),
Projects(projects::Options),
Secrets(secrets::Options),
Deploy(deploy::Options),
#[clap(name = "whoami", alias = "info", alias = "ctx")]
Whoami(whoami::Options),
Ignite(ignite::Options),
Link(link::Options),
#[cfg(feature = "update")]
Update(update::Options),
Containers(containers::Options),
Gateways(gateways::Options),
Domains(domains::Options),
#[clap(name = "completions", alias = "complete", hide = cfg!(not(feature = "update")))]
Completions(completions::Options),
}
pub async fn handle_command(command: Commands, mut state: State) -> Result<()> {
match command {
Commands::Auth(options) => auth::handle(options, state).await,
#[cfg(feature = "update")]
Commands::Update(options) => update::handle(options, state).await,
Commands::Completions(options) => {
completions::handle(options, state);
Ok(())
}
authorized_command => {
state.login(None).await?;
match authorized_command {
Commands::Auth(_) | Commands::Completions(_) => {
unreachable!()
}
#[cfg(feature = "update")]
Commands::Update(_) => unreachable!(),
Commands::Projects(options) => projects::handle(options, state).await,
Commands::Secrets(options) => secrets::handle(options, state).await,
Commands::Deploy(options) => deploy::handle(options, state).await,
Commands::Whoami(options) => whoami::handle(&options, state),
Commands::Ignite(options) => ignite::handle(options, state).await,
Commands::Link(options) => link::handle(options, state).await,
Commands::Containers(options) => containers::handle(options, state).await,
Commands::Gateways(options) => gateways::handle(options, state).await,
Commands::Domains(options) => domains::handle(options, state).await,
}
}
}
}