1use crate::ui::PremiumUI;
3use clap::{Arg, Command};
4use console::style;
5
6mod api_client;
7mod commands;
8mod models;
9mod ui;
10
11#[tokio::main]
12async fn main() -> anyhow::Result<()> {
13 let ui = PremiumUI::new();
14
15 let cli = Command::new("omni")
16 .about(format!(
17 "{}",
18 style("OmniOrchestrator - Self-Hosted Cloud Platform CLI")
19 .cyan()
20 .bold()
21 ))
22 .subcommand(
23 Command::new("init")
24 .about(format!(
25 "{}",
26 style("Initialize cloud environment with OmniOrchestrator").green()
27 ))
28 .arg(
29 Arg::new("force")
30 .long("force")
31 .help("Force re-initialization even if config exists")
32 .required(false)
33 .action(clap::ArgAction::SetTrue),
34 ),
35 )
36 .subcommand(Command::new("version").about(format!(
37 "{}",
38 style("Initialize cloud environment with OmniOrchestrator").green()
39 )))
40 .subcommand(
41 Command::new("welcome").about(format!("{}", style("Display welcome message").green())),
42 )
43 .subcommand(
44 Command::new("hosts").about(format!("{}", style("List configured SSH hosts").green())),
45 )
46 .subcommand(Command::new("status").about(format!(
47 "{}",
48 style("Check OmniOrchestrator status").green()
49 )))
50 .subcommand(
51 Command::new("up")
52 .about(format!(
53 "{}",
54 style("Deploy application components").green()
55 ))
56 .arg(
57 Arg::new("environment")
58 .long("env")
59 .help(&format!(
60 "Target environment {}",
61 style("[dev/staging/prod]").yellow()
62 ))
63 .required(false),
64 ),
65 )
66 .subcommand(
67 Command::new("push")
68 .about(format!(
69 "{}",
70 style("Push images to container registry").green()
71 ))
72 .arg(
73 Arg::new("tag")
74 .long("tag")
75 .help(&format!("Image tag {}", style("[latest]").yellow()))
76 .required(false),
77 ),
78 )
79 .subcommand(
80 Command::new("scale")
81 .about(format!("{}", style("Scale application components").green()))
82 .arg(
83 Arg::new("component")
84 .long("component")
85 .help(&format!(
86 "Component to scale {}",
87 style("[frontend/backend/database]").yellow()
88 ))
89 .required(false),
90 )
91 .arg(
92 Arg::new("replicas")
93 .long("replicas")
94 .help(&format!("Number of replicas {}", style("[1-10]").yellow()))
95 .required(false),
96 ),
97 )
98 .subcommand(
99 Command::new("logs")
100 .about(format!("{}", style("View application logs").green()))
101 .arg(
102 Arg::new("host")
103 .long("host")
104 .help("Host to view logs from")
105 .required(false),
106 )
107 .arg(
108 Arg::new("service")
109 .long("service")
110 .help("Service to view logs for")
111 .required(false),
112 )
113 .arg(
114 Arg::new("tail")
115 .long("tail")
116 .help("Number of lines to show")
117 .default_value("100"),
118 ),
119 )
120 .subcommand(
121 Command::new("service")
122 .about(format!(
123 "{}",
124 style("Manage OmniOrchestrator services").green()
125 ))
126 .subcommand(
127 Command::new("restart")
128 .about("Restart a service")
129 .arg(Arg::new("host").required(true))
130 .arg(Arg::new("service").required(true)),
131 )
132 .subcommand(
133 Command::new("stop")
134 .about("Stop a service")
135 .arg(Arg::new("host").required(true))
136 .arg(Arg::new("service").required(true)),
137 )
138 .subcommand(
139 Command::new("start")
140 .about("Start a service")
141 .arg(Arg::new("host").required(true))
142 .arg(Arg::new("service").required(true)),
143 ),
144 )
145 .subcommand(
146 Command::new("backup")
147 .about(format!("{}", style("Manage backup operations").green()))
148 .subcommand(Command::new("now").about("Trigger an immediate backup"))
149 .subcommand(Command::new("list").about("List available backups"))
150 .subcommand(
151 Command::new("restore")
152 .about("Restore from a backup")
153 .arg(Arg::new("id").required(true)),
154 ),
155 )
156 .subcommand(
157 Command::new("rollback")
158 .about(format!("{}", style("Rollback to previous version").green()))
159 .arg(
160 Arg::new("version")
161 .long("version")
162 .help("Version to rollback to")
163 .required(false),
164 ),
165 )
166 .subcommand(
167 Command::new("config")
168 .about(format!(
169 "{}",
170 style("Manage application configuration").green()
171 ))
172 .subcommand(Command::new("view").about("View current configuration"))
173 .subcommand(Command::new("edit").about("Edit configuration"))
174 .subcommand(Command::new("reset").about("Reset configuration to defaults")),
175 )
176 .get_matches();
177
178 match cli.subcommand() {
179 Some(("init", _)) => ui.init_environment().await?,
181 Some(("hosts", _)) => ui.list_ssh_hosts().await?,
182 Some(("status", _)) => ui.status_interactive().await?,
183
184 Some(("up", _)) => ui.deploy_interactive().await?,
186 Some(("push", _)) => ui.push_interactive().await?,
187 Some(("scale", _)) => ui.scale_interactive().await?,
188 Some(("logs", _)) => ui.logs_interactive().await?,
189 Some(("rollback", _)) => ui.rollback_interactive().await?,
190
191 Some(("service", subcommand)) => match subcommand.subcommand() {
193 Some(("restart", _)) => {
194 println!("{}", style("Service restart not yet implemented").yellow())
195 }
196 Some(("stop", _)) => println!("{}", style("Service stop not yet implemented").yellow()),
197 Some(("start", _)) => {
198 println!("{}", style("Service start not yet implemented").yellow())
199 }
200 _ => println!(
201 "{}",
202 style("Use 'omni service --help' for available commands").yellow()
203 ),
204 },
205
206 Some(("backup", subcommand)) => match subcommand.subcommand() {
208 Some(("now", _)) => println!("{}", style("Backup now not yet implemented").yellow()),
209 Some(("list", _)) => println!("{}", style("Backup list not yet implemented").yellow()),
210 Some(("restore", _)) => {
211 println!("{}", style("Backup restore not yet implemented").yellow())
212 }
213 _ => println!(
214 "{}",
215 style("Use 'omni backup --help' for available commands").yellow()
216 ),
217 },
218
219 Some(("config", subcommand)) => match subcommand.subcommand() {
221 Some(("view", _)) => ui.config_view().await?,
222 Some(("edit", _)) => ui.config_edit().await?,
223 Some(("reset", _)) => ui.config_reset().await?,
224 _ => ui.config_view().await?,
225 },
226
227 Some(("version", _)) => {
229 println!(
230 "{} {}",
231 style("OmniOrchestrator").yellow(),
232 style(version::version!()).yellow()
233 );
234 }
235
236 Some(("welcome", _)) => {
238 ui.display_welcome()?;
239 }
240
241 _ => {
243 ui.display_welcome()?;
244
245 println!(
246 "\n{}",
247 style("OMNI ORCHESTRATOR COMMANDS:").magenta().bold()
248 );
249 println!(
250 " {} {}",
251 style("init").cyan(),
252 style("Initialize cloud environment").dim()
253 );
254 println!(
255 " {} {}",
256 style("hosts").cyan(),
257 style("List configured SSH hosts").dim()
258 );
259 println!(
260 " {} {}",
261 style("status").cyan(),
262 style("Check OmniOrchestrator status").dim()
263 );
264 println!(
265 " {} {}",
266 style("service").cyan(),
267 style("Manage OmniOrchestrator services").dim()
268 );
269 println!(
270 " {} {}",
271 style("backup").cyan(),
272 style("Manage backup operations").dim()
273 );
274
275 println!("\n{}", style("APPLICATION COMMANDS:").magenta().bold());
276 println!(
277 " {} {}",
278 style("up").cyan(),
279 style("Deploy your application").dim()
280 );
281 println!(
282 " {} {}",
283 style("push").cyan(),
284 style("Push images to registry").dim()
285 );
286 println!(
287 " {} {}",
288 style("scale").cyan(),
289 style("Scale application components").dim()
290 );
291 println!(
292 " {} {}",
293 style("logs").cyan(),
294 style("View application logs").dim()
295 );
296 println!(
297 " {} {}",
298 style("rollback").cyan(),
299 style("Rollback to previous version").dim()
300 );
301 println!(
302 " {} {}",
303 style("config").cyan(),
304 style("Manage application configuration").dim()
305 );
306 println!(
307 "\n{}",
308 style("Use --help with any command for more information.").yellow()
309 );
310 }
311 }
312
313 Ok(())
314}