feat!: CLI init
- Added CLI, does not perform any action now, but accepts arguments correctly BREAKING CHANGE: Removed main.rs file
This commit is contained in:
parent
f5180a559b
commit
119b7bce9c
4 changed files with 117 additions and 4 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
|
@ -59,6 +59,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -73,6 +74,18 @@ dependencies = [
|
|||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.6"
|
||||
|
|
@ -97,6 +110,12 @@ version = "0.16.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.12.1"
|
||||
|
|
@ -181,6 +200,7 @@ name = "squad-quest"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_derive",
|
||||
"serde",
|
||||
"toml",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = "4.5.53"
|
||||
clap = { version = "4.5.53", features = ["derive"] }
|
||||
clap_derive = "4.5.49"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
toml = "0.9.8"
|
||||
|
|
|
|||
95
src/bin/cli.rs
Normal file
95
src/bin/cli.rs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser,Subcommand,Args,ValueEnum};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
struct Cli {
|
||||
/// Path to config
|
||||
#[arg(short, long)]
|
||||
config: PathBuf,
|
||||
/// Object to make operation on
|
||||
#[command(subcommand)]
|
||||
command: Objects,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Objects {
|
||||
/// Operations on the quests
|
||||
#[command(subcommand)]
|
||||
Quest(QuestCommands)
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||
enum QuestDifficulty {
|
||||
/// Easy quest
|
||||
Easy,
|
||||
/// Normal quest
|
||||
Normal,
|
||||
/// Hard quest
|
||||
Hard,
|
||||
/// Special case of hard quests.
|
||||
Secret
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum QuestCommands {
|
||||
/// List available quests
|
||||
List(QuestListArgs),
|
||||
/// Create new quest and automatically assign it id
|
||||
Create(QuestCreateArgs),
|
||||
/// Update existing quest
|
||||
Update(QuestUpdateArgs),
|
||||
/// Delete quest
|
||||
Delete(QuestDeleteArgs),
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct QuestListArgs {
|
||||
/// Only list id and name of the quest
|
||||
#[arg(short, long)]
|
||||
short: bool
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct QuestCreateArgs {
|
||||
/// Difficulty of the quest
|
||||
#[arg(value_enum)]
|
||||
difficulty: QuestDifficulty,
|
||||
/// Reward for the quest
|
||||
reward: u32,
|
||||
/// Name of the quest
|
||||
name: String,
|
||||
/// Visible description of the quest
|
||||
description: String,
|
||||
/// Answer for the quest for admins
|
||||
answer: String
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct QuestUpdateArgs {
|
||||
/// Id of the quest to update
|
||||
id: u16,
|
||||
/// Difficulty of the quest
|
||||
#[arg(value_enum)]
|
||||
difficulty: QuestDifficulty,
|
||||
/// Reward for the quest
|
||||
reward: u32,
|
||||
/// Name of the quest
|
||||
name: String,
|
||||
/// Visible description of the quest
|
||||
description: String,
|
||||
/// Answer for the quest for admins
|
||||
answer: String
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct QuestDeleteArgs {
|
||||
/// Id of the quest to delete
|
||||
id: u16
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _cli = Cli::parse();
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue