Skip to main content

over_there/cli/opts/
mod.rs

1pub mod client;
2mod parsers;
3pub mod schema;
4pub mod server;
5pub mod types;
6
7use clap::Clap;
8use std::time::Duration;
9use strum::VariantNames;
10
11#[derive(Clap, Debug)]
12pub enum Command {
13    /// Launches a client to talk to a server
14    #[clap(name = "client")]
15    Client(client::ClientCommand),
16
17    /// Launches a server to listen for incoming requests
18    #[clap(name = "server")]
19    Server(server::ServerCommand),
20
21    /// Prints schema information in JSON format
22    #[clap(name = "schema")]
23    Schema(schema::SchemaCommand),
24}
25
26impl Command {
27    pub fn common_opts(&self) -> Option<&CommonOpts> {
28        match self {
29            Self::Client(c) => Some(&c.opts),
30            Self::Server(s) => Some(&s.opts),
31            Self::Schema(_) => None,
32        }
33    }
34}
35
36#[derive(Clap, Debug)]
37#[clap(author, about, version)]
38pub struct Opts {
39    #[clap(subcommand)]
40    pub command: Command,
41}
42
43#[derive(Clap, Debug)]
44pub struct CommonOpts {
45    /// Timeout (in seconds) used when communicating across the network
46    #[clap(long, parse(try_from_str = parsers::parse_duration_secs), default_value = "5")]
47    pub timeout: Duration,
48
49    /// Time-to-live (in seconds) for collecting all packets in a msg
50    #[clap(long, parse(try_from_str = parsers::parse_duration_secs), default_value = "300")]
51    pub packet_ttl: Duration,
52
53    /// Maximum size of internal message passing between reader, writer, and
54    /// executor loops
55    #[clap(long, default_value = "1000")]
56    pub internal_buffer_size: usize,
57
58    /// Transportation medium used in communication between client and server
59    #[clap(
60        short = "t", 
61        long, 
62        parse(try_from_str), 
63        possible_values = &types::Transport::VARIANTS, 
64        default_value = types::Transport::Udp.as_ref(),
65    )]
66    pub transport: types::Transport,
67
68    /// Type of encryption to use with incoming and outgoing msgs
69    #[clap(
70        short = "e", 
71        long, 
72        parse(try_from_str), 
73        possible_values = &types::Encryption::VARIANTS, 
74        default_value = types::Encryption::None.as_ref(),
75    )]
76    pub encryption: types::Encryption,
77
78    /// Key to use with encryption
79    #[clap(long = "ekey")]
80    pub encryption_key: Option<String>,
81
82    /// Type of authentication to use with incoming and outgoing msgs
83    #[clap(
84        short = "a",
85        long,
86        parse(try_from_str),
87        possible_values = &types::Authentication::VARIANTS,
88        default_value = types::Authentication::None.as_ref(),
89    )]
90    pub authentication: types::Authentication,
91
92    /// Key to use with encryption
93    #[clap(long = "akey")]
94    pub authentication_key: Option<String>,
95}