xianyun_cli/commands/
mod.rs1pub mod ca;
7pub mod config;
8pub mod deploy;
9pub mod destroy;
10pub mod doctor;
11pub mod down;
12pub mod editmodeprocesssupervisor;
13pub mod k9s;
14pub mod kubectl;
15pub mod logs;
16pub mod registry;
17pub mod run;
18pub mod setkubecontext;
19pub mod status;
20pub mod stern;
21pub mod tool;
22pub mod up;
23pub mod update;
24pub mod updateetchosts;
25pub mod version;
26
27use xianyun_core::config::global::{Context, with_context};
28
29use crate::{Cli, Commands};
30
31fn command_name(cli: &Cli) -> &'static str {
34 match &cli.command {
35 Commands::Up(_) => "up",
36 Commands::Down(_) => "down",
37 Commands::Destroy(_) => "destroy",
38 Commands::Status(_) => "status",
39 Commands::Update(_) => "update",
40 Commands::Deploy(_) => "deploy",
41 Commands::UpdateEtcHosts(_) => "update-etc-hosts",
42 Commands::SetKubeContext(_) => "set-kube-context",
43 Commands::Run(_) => "run",
44 Commands::Config(_) => "config",
45 Commands::Version(_) => "version",
46 Commands::EditModeProcessSupervisor(_) => "edit-mode-process-supervisor",
47 Commands::Ca(_) => "ca",
48 Commands::Kubectl(_) => "kubectl",
49 Commands::K9s(_) => "k9s",
50 Commands::Stern(_) => "stern",
51 Commands::Registry(_) => "registry",
52 Commands::Logs(_) => "logs",
53 Commands::Doctor(_) => "doctor",
54 Commands::Tool(_) => "tool",
55 }
56}
57
58pub fn dispatch(cli: &Cli) -> anyhow::Result<()> {
75 crate::hooks::init_logging(cli)?;
79
80 let ctx = if crate::hooks::should_load_config(Some(command_name(cli))) {
81 let global_config = crate::hooks::before_hook(cli, Some(command_name(cli)))?;
82 with_context(Context::default(), global_config)
83 } else {
84 Context::default()
85 };
86
87 match &cli.command {
88 Commands::Up(args) => up::run(args, &ctx),
89 Commands::Down(args) => down::run(args, &ctx),
90 Commands::Destroy(args) => destroy::run(args, &ctx),
91 Commands::Status(args) => status::run(args, &ctx),
92 Commands::Update(args) => update::run(args, &ctx),
93 Commands::Deploy(args) => deploy::run(args, &ctx),
94 Commands::UpdateEtcHosts(args) => updateetchosts::run(args, &ctx),
95 Commands::SetKubeContext(args) => setkubecontext::run(args, &ctx),
96 Commands::Run(args) => run::run(args, &ctx, cli),
97 Commands::Config(args) => config::run(args, &ctx),
98 Commands::Version(args) => version::run(args),
99 Commands::EditModeProcessSupervisor(args) => editmodeprocesssupervisor::run(args, &ctx),
100 Commands::Ca(args) => ca::run(args, &ctx),
101 Commands::Kubectl(args) => kubectl::run(args, &ctx),
102 Commands::K9s(args) => k9s::run(args, &ctx),
103 Commands::Stern(args) => stern::run(args, &ctx),
104 Commands::Registry(args) => registry::run(args),
105 Commands::Logs(args) => logs::run(args, &ctx),
106 Commands::Doctor(args) => doctor::run(args, &ctx),
107 Commands::Tool(args) => tool::run(args, &ctx),
108 }
109}