p2p_chat/app/args.rs
1//! This module defines the command-line arguments for the application.
2use clap::Parser;
3
4/// Defines the command-line arguments for the application.
5///
6/// This struct is used by the `clap` crate to parse command-line arguments.
7#[derive(Parser, Debug, Clone)]
8#[command(name = "p2p-messenger")]
9#[command(about = "A P2P E2E encrypted messenger")]
10pub struct AppArgs {
11 /// If set, the application will run in mailbox node mode.
12 #[arg(long, help = "Run in mailbox node mode")]
13 pub mailbox: bool,
14
15 /// The port to listen on.
16 /// If not specified, a random free port will be used.
17 #[arg(long, help = "Port to listen on (random free port if not specified)")]
18 pub port: Option<u16>,
19
20 /// The directory where data will be stored.
21 #[arg(long, default_value = "data", help = "Data directory")]
22 pub data_dir: String,
23
24 /// If set, storage encryption will be enabled.
25 #[arg(long, help = "Enable storage encryption")]
26 pub encrypt: bool,
27
28 /// The password to use for storage encryption.
29 /// This can also be set using the `P2P_MESSENGER_PASSWORD` environment variable.
30 #[arg(
31 long = "encryption-password",
32 help = "Password used for storage encryption (or set P2P_MESSENGER_PASSWORD)"
33 )]
34 pub encryption_password: Option<String>,
35
36 /// The port for the Web UI.
37 /// If not specified, a random free port will be used.
38 #[arg(long, help = "Web UI port (random free port if not specified)")]
39 pub web_port: Option<u16>,
40}
41
42impl AppArgs {
43 /// Parses command-line arguments from the environment.
44 ///
45 /// This function uses the `clap` crate to parse the command-line arguments
46 /// provided to the application and returns a new `AppArgs` instance.
47 pub fn from_cli() -> Self {
48 <Self as Parser>::parse()
49 }
50}