veloren_voxygen/
cli.rs

1//! NOTE: Some of these arguments are used by airshipper, so those needs to be
2//! kept fairly stable (probably with some sort of migration period if we need
3//! to modify the name or semantics).
4//!
5//! The arguments used by airshipper are:
6//! * `server`
7//!
8//! Airshipper should only use arguments listed above! Since we will not try to
9//! be careful about their stability otherwise.
10//!
11//! Likewise Airshipper should only use the following subcommands:
12//! * `ListWgpuBackends`
13use std::str::FromStr;
14
15use clap::{Parser, Subcommand};
16use common_net::msg::ClientType;
17
18#[derive(Parser, Clone)]
19pub struct Args {
20    /// Value to auto-fill into the server field.
21    ///
22    /// This allows passing in server selection performed in airshipper.
23    #[clap(short, long)]
24    pub server: Option<String>,
25
26    /// The [`ClientType`] voxygen will use to initialize the client.
27    ///
28    /// The only supported values are currently `game` and `silent_spectator`,
29    /// the latter one only being usable by moderators.
30    #[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    /// List available wgpu backends. This is called by Airshipper to show a
40    /// dropbox of available backends.
41    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}