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 /// List available wgpu devices. This is called by Airshipper to show a
43 /// dropbox of available devices.
44 ListWgpuDevices,
45}
46
47#[derive(Clone)]
48pub struct VoxygenClientType(pub ClientType);
49
50impl FromStr for VoxygenClientType {
51 type Err = String;
52
53 fn from_str(s: &str) -> Result<Self, Self::Err> {
54 Ok(Self(match s.to_lowercase().as_str() {
55 "game" => ClientType::Game,
56 "silent_spectator" => ClientType::SilentSpectator,
57 c_type => return Err(format!("Invalid client type for voxygen: {c_type}")),
58 }))
59 }
60}
61
62impl std::fmt::Display for VoxygenClientType {
63 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64 write!(f, "{}", match self.0 {
65 ClientType::Game => "game",
66 ClientType::ChatOnly => "chat_only",
67 ClientType::SilentSpectator => "silent_spectator",
68 ClientType::Bot { .. } => "bot",
69 })
70 }
71}