cryptic_tui/
cli.rs

1//! Command-line argument parsing.
2//!
3//! This module handles parsing of command-line arguments using the `clap` crate.
4//!
5//! # Arguments
6//!
7//! - `--node <NODE>` - Erlang node name to connect to (e.g., admin@localhost)
8//! - `--cookie <COOKIE>` - Erlang cookie for authentication (defaults to ~/.erlang.cookie)
9//!
10//! # Examples
11//!
12//! ```bash
13//! # Connect with explicit cookie
14//! cryptic-tui --node admin@localhost --cookie mycookie
15//!
16//! # Use cookie from ~/.erlang.cookie
17//! cryptic-tui --node admin@localhost
18//! ```
19
20use clap::Parser;
21
22/// Cryptic Terminal UI - Secure messaging interface
23#[derive(Parser, Debug)]
24#[command(name = "cryptic-tui")]
25#[command(version, about, long_about = None)]
26pub struct CliArgs {
27    /// Erlang node name to connect to (e.g., admin@localhost)
28    #[arg(long, value_name = "NODE")]
29    pub node: Option<String>,
30
31    /// Erlang cookie for authentication (if not set, reads from ~/.erlang.cookie)
32    #[arg(long, value_name = "COOKIE")]
33    pub cookie: Option<String>,
34}
35
36impl CliArgs {
37    /// Parse command-line arguments.
38    ///
39    /// # Returns
40    ///
41    /// Parsed [`CliArgs`] struct with node and cookie values.
42    pub fn parse_args() -> Self {
43        Self::parse()
44    }
45
46    /// Get the Erlang node name if provided.
47    ///
48    /// # Returns
49    ///
50    /// Optional reference to the node name string.
51    pub fn get_node_name(&self) -> Option<&str> {
52        self.node.as_deref()
53    }
54
55    /// Get the Erlang cookie if provided.
56    ///
57    /// # Returns
58    ///
59    /// Optional reference to the cookie string.
60    pub fn get_cookie(&self) -> Option<&str> {
61        self.cookie.as_deref()
62    }
63}