1use std::str::FromStr;
14
15use clap::{Parser, Subcommand};
16use common_net::msg::ClientType;
17
18#[derive(Parser, Clone)]
19pub struct Args {
20 #[clap(short, long)]
24 pub server: Option<String>,
25
26 #[clap(short, long, env = "VELOREN_CLIENT_TYPE", default_value_t = VoxygenClientType(ClientType::Game))]
31 pub client_type: VoxygenClientType,
32
33 #[clap(subcommand)]
34 pub command: Option<Commands>,
35}
36
37#[derive(Subcommand, Clone)]
38pub enum Commands {
39 ListWgpuBackends,
42}
43
44#[derive(Clone)]
45pub struct VoxygenClientType(pub ClientType);
46
47impl FromStr for VoxygenClientType {
48 type Err = String;
49
50 fn from_str(s: &str) -> Result<Self, Self::Err> {
51 Ok(Self(match s.to_lowercase().as_str() {
52 "game" => ClientType::Game,
53 "silent_spectator" => ClientType::SilentSpectator,
54 c_type => return Err(format!("Invalid client type for voxygen: {c_type}")),
55 }))
56 }
57}
58
59impl std::fmt::Display for VoxygenClientType {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 write!(f, "{}", match self.0 {
62 ClientType::Game => "game",
63 ClientType::ChatOnly => "chat_only",
64 ClientType::SilentSpectator => "silent_spectator",
65 ClientType::Bot { .. } => "bot",
66 })
67 }
68}