From 78409b6141fb89e5d3f5f09fc7be5bc7caf8657a Mon Sep 17 00:00:00 2001 From: Gustavo Dias de Aguiar <79119534+gustavodiasag@users.noreply.github.com> Date: Fri, 31 May 2024 11:59:39 -0300 Subject: [PATCH] feat(cli): initial structure (#40) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Eduardo Lemos Co-authored-by: Luiz Felipe Gonçalves --- Cargo.lock | 7 ++++++ Cargo.toml | 2 +- cli/Cargo.toml | 10 ++++++++ cli/src/main.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 cli/Cargo.toml create mode 100644 cli/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index d5c3a7a..09be75d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,6 +261,13 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "cli" +version = "0.1.0" +dependencies = [ + "clap", +] + [[package]] name = "colorchoice" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 0d73ef2..86a7ad4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/*", "ctl", "proto", "worker"] +members = ["cli", "crates/*", "ctl", "proto", "worker"] resolver = "2" [workspace.package] diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..71f173c --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "cli" +version.workspace = true +edition.workspace = true + +[lints] +workspace = true + +[dependencies] +clap.workspace = true diff --git a/cli/src/main.rs b/cli/src/main.rs new file mode 100644 index 0000000..1147705 --- /dev/null +++ b/cli/src/main.rs @@ -0,0 +1,66 @@ +use std::net::SocketAddr; + +use clap::{Parser, Subcommand}; + +#[derive(Debug, Parser)] +pub struct Cli { + #[command(subcommand)] + cmd: Cmd, +} + +#[derive(Debug, Subcommand)] +pub enum Cmd { + #[clap(subcommand)] + Node(NodeCmd), + #[clap(subcommand)] + Service(ServiceCmd), +} + +#[derive(Debug, Subcommand)] +pub enum NodeCmd { + List, + Show { + address: SocketAddr, + }, + #[clap(subcommand)] + Worker(WorkerCmd), +} + +#[derive(Debug, Subcommand)] +pub enum WorkerCmd { + Remove { address: SocketAddr }, +} + +#[derive(Debug, Subcommand)] +pub enum ServiceCmd { + List, + Show { id: String }, + Deploy { id: String, image: String }, + Terminate { id: String }, +} + +fn main() { + let cli = Cli::parse(); + + match cli.cmd { + Cmd::Node(cmd) => handle_node(&cmd), + Cmd::Service(cmd) => handle_service(&cmd), + } +} + +fn handle_node(cmd: &NodeCmd) { + match cmd { + NodeCmd::List => todo!(), + NodeCmd::Show { .. } => todo!(), + NodeCmd::Worker(_) => todo!(), + } +} + +fn handle_service(cmd: &ServiceCmd) { + match cmd { + ServiceCmd::List => todo!(), + ServiceCmd::Show { .. } => todo!(), + ServiceCmd::Deploy { .. } => todo!(), + ServiceCmd::Terminate { .. } => todo!(), + } +}