Initial rust project structure with clap
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
1
src/cmd/mod.rs
Normal file
1
src/cmd/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod new;
|
3
src/cmd/new.rs
Normal file
3
src/cmd/new.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub fn new_command(server_name: &str, minecraft_version: &str) {
|
||||
println!("Creating new server with name '{}' using version '{}'.", server_name, minecraft_version);
|
||||
}
|
33
src/main.rs
Normal file
33
src/main.rs
Normal file
@ -0,0 +1,33 @@
|
||||
mod cmd;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(name = "Minecraft server management tool", author, version, about = "Bit Goblin's Minecraft server management tool.", long_about = None)]
|
||||
#[clap(propagate_version = true)]
|
||||
struct Cli {
|
||||
#[clap(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
// new server subcommand
|
||||
#[clap(name = "new", about = "Create a new Minecraft java edition server instance.")]
|
||||
New {
|
||||
#[clap(short = 'n', long, required = true, help = "[REQUIRED] The name for your new server")]
|
||||
server_name: String,
|
||||
#[clap(short = 'm', long, required = true, help = "[REQUIRED] Minecraft Java Edition server version to use.")]
|
||||
minecraft_version: String,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// start the Clap CLI
|
||||
let cli = Cli::parse();
|
||||
|
||||
// map subcommands back to the main command
|
||||
match &cli.command {
|
||||
Commands::New { server_name, minecraft_version } => cmd::new::new_command(&server_name, &minecraft_version),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user