feat: Parse commands from args
This commit is contained in:
parent
9580f88c2f
commit
dd124d11ae
2 changed files with 36 additions and 2 deletions
|
@ -6,6 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5", features = ["cargo", "derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
cc-cli = "0.1.5"
|
||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -1,3 +1,36 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())]
|
||||
struct Commands {
|
||||
#[clap(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
#[derive(Parser, Debug)]
|
||||
enum Command {
|
||||
Init,
|
||||
#[clap(subcommand)]
|
||||
Server(Server),
|
||||
}
|
||||
#[derive(Parser, Debug)]
|
||||
enum Server {
|
||||
Init,
|
||||
Start,
|
||||
}
|
||||
fn main() {
|
||||
let commands = Commands::parse();
|
||||
|
||||
match commands.command {
|
||||
Command::Init => {
|
||||
println!("Init command");
|
||||
}
|
||||
Command::Server(server) => match server {
|
||||
Server::Init => {
|
||||
println!("Server Init command");
|
||||
}
|
||||
Server::Start => {
|
||||
println!("Server Start command");
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue