use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(
name = "odin",
version,
author,
about = "Valheim Server Manager — manage your Dockerized Valheim server"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Init,
Health,
Fix {
#[command(subcommand)]
sub: FixSub,
},
Start,
Stop,
Restart,
Down,
Logs {
#[arg(default_value = "50")]
lines: usize,
},
Status,
StatusPassword,
Update,
Backup,
ClearBackups,
Snapshot,
Shell,
RestoreWorlds,
SyncWorlds {
#[arg(long)]
help_guide: bool,
},
FilterMods,
DownloadMods,
InstallMods,
ClearMods,
ApplyPatch,
VerifyPatch,
}
#[derive(Subcommand, Debug)]
pub enum FixSub {
Permission,
}
#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;
#[test]
fn parse_init() {
let cli = Cli::try_parse_from(["odin", "init"]).unwrap();
assert!(matches!(cli.command, Commands::Init));
}
#[test]
fn parse_start() {
let cli = Cli::try_parse_from(["odin", "start"]).unwrap();
assert!(matches!(cli.command, Commands::Start));
}
#[test]
fn parse_logs_default() {
let cli = Cli::try_parse_from(["odin", "logs"]).unwrap();
match cli.command {
Commands::Logs { lines } => assert_eq!(lines, 50),
_ => panic!("expected Logs"),
}
}
#[test]
fn parse_logs_custom() {
let cli = Cli::try_parse_from(["odin", "logs", "100"]).unwrap();
match cli.command {
Commands::Logs { lines } => assert_eq!(lines, 100),
_ => panic!("expected Logs"),
}
}
#[test]
fn parse_fix_permission() {
let cli = Cli::try_parse_from(["odin", "fix", "permission"]).unwrap();
assert!(matches!(
cli.command,
Commands::Fix {
sub: FixSub::Permission
}
));
}
#[test]
fn parse_sync_worlds_help() {
let cli = Cli::try_parse_from(["odin", "sync-worlds", "--help-guide"]).unwrap();
match cli.command {
Commands::SyncWorlds { help_guide } => assert!(help_guide),
_ => panic!("expected SyncWorlds"),
}
}
#[test]
fn parse_apply_patch() {
let cli = Cli::try_parse_from(["odin", "apply-patch"]).unwrap();
assert!(matches!(cli.command, Commands::ApplyPatch));
}
#[test]
fn parse_verify_patch() {
let cli = Cli::try_parse_from(["odin", "verify-patch"]).unwrap();
assert!(matches!(cli.command, Commands::VerifyPatch));
}
}