cli/
parser.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
pub use clap::Parser;

/// Represents command line arguments for a client in a CLI application.
///
/// This struct is used to parse and store command line arguments specific to the client part of an application.
/// It leverages the `clap` crate for argument parsing.
///
/// ## Fields
/// - `hostname`: A string specifying the hostname. Defaults to "localhost".
/// - `port`: A 16-bit unsigned integer specifying the port number. Defaults to 8787.
/// - `worker_name`: A string specifying the name of the worker. Defaults to "worker".
///
/// ## Example
/// Command line usage might look like this:
/// ```sh
/// worker -H 192.168.1.0 -P 8787 -N my_group_name
/// ```
#[derive(Parser, Debug, Clone)]
pub struct CliClientArgs {
    /// Optional: The hostname of the client.
    /// Default: "localhost"
    #[clap(long = "hostname", default_value = "localhost")]
    pub hostname: String,

    /// Optional: The port number to connect on.
    /// Default: 8787
    #[clap(short = 'P', long = "port", default_value = "8787")]
    pub port: u16,

    /// Optional: The name of the worker.
    /// Default: "worker"
    #[clap(short = 'N', long = "name", default_value = "worker")]
    pub worker_name: String,

    /// Optional: Add a flag to enable/disable logging.
    /// Default: 0
    #[clap(short = 'v', long = "verbose",  action = clap::ArgAction::Count)]
    pub verbose: u8,

    /// Optional: Add a flag to enable/disable debug mode.
    /// Default: 0
    #[clap(short = 'd', long = "debug", action = clap::ArgAction::Count)]
    pub debug: u8,

    /// Optional: Add a flag to enable/disable trace mode.
    /// Default: 0
    #[clap(short = 't', long = "trace", action = clap::ArgAction::Count)]
    pub trace: u8,

    /// Optional: Add a flag to enable/disable opening the browser.
    /// Default: false
    #[clap(short = 'o', long = "open", default_value = "false")]
    pub open: bool,

    /// Optional: Add a flag to save the image to a file.
    /// Default: false
    #[clap(short = 's', long = "save", default_value = "false")]
    pub save: bool,
}

/// Represents command line arguments for a server in a CLI application.
///
/// Similar to `CliClientArgs`, this struct is for parsing server-specific command line arguments.
/// It uses the `clap` crate for parsing.
///
/// ## Fields
/// - `hostname`: A string specifying the hostname. Defaults to "localhost".
/// - `port`: A 16-bit unsigned integer specifying the port number. Defaults to 8787.
/// - `verbose`: A boolean flag to enable/disable logging. Defaults to false.
/// - `debug`: A boolean flag to enable/disable debug mode. Defaults to false.
/// - `width`: A 16-bit unsigned integer specifying the width of the window. Defaults to 1200.
/// - `height`: A 16-bit unsigned integer specifying the height of the window. Defaults to 1200.
///
/// ## Example
/// Command line usage for the server might be:
/// ```sh
/// server -H 192.168.1.0 -P 8787
/// ```
#[derive(Parser, Debug, Clone)]
pub struct CliServerArgs {
    /// The hostname of the server.
    /// Default: "localhost"
    #[clap(long = "hostname", default_value = "localhost")]
    pub hostname: String,

    /// The port number the server listens on.
    /// Default: 8787
    #[clap(short = 'P', long = "port", default_value = "8787")]
    pub port: u16,

    /// Optional: Add a flag to enable/disable logging.
    /// Default: 0
    #[clap(short = 'v', long = "verbose",  action = clap::ArgAction::Count)]
    pub verbose: u8,

    /// Optional: Add a flag to enable/disable debug mode.
    /// Default: 0
    #[clap(short = 'd', long = "debug", action = clap::ArgAction::Count)]
    pub debug: u8,

    /// Optional: Add a flag to enable/disable trace mode.
    /// Default: 0
    #[clap(short = 't', long = "trace", action = clap::ArgAction::Count)]
    pub trace: u8,

    /// Optional: Add a flag to edit the width and height of the window.
    /// Default: 1200
    #[clap(long = "width", default_value = "1200")]
    pub width: u16,

    /// Optional: Add a flag to edit the width and height of the window.
    /// Default: 1200
    #[clap(long = "height", default_value = "1200")]
    pub height: u16,
}

/// An enumeration representing the possible types of command line arguments.
///
/// This enum helps in differentiating between client and server command line arguments.
/// It is a common practice in CLI applications to have different sets of arguments for different modes (client/server).
///
/// ## Variants
/// - `Client(CliClientArgs)`: Command line arguments specific to the client.
/// - `Server(CliServerArgs)`: Command line arguments specific to the server.
#[derive(Clone)]
pub enum CliArgs {
    Client(CliClientArgs),
    Server(CliServerArgs),
}