pub struct Arguments {
pub control_address: String,
pub control_port: Option<u16>,
pub user_provided_port: bool,
pub control_socket: String,
pub user_provided_socket: bool,
pub tor_path: String,
pub run_cmd: Option<String>,
pub run_path: Option<String>,
pub disable_color: bool,
pub print_help: bool,
}Expand description
Parsed command-line arguments for the interpreter.
This struct holds all configuration options that can be specified via command-line arguments when launching the interpreter.
§Default Values
| Field | Default |
|---|---|
control_address | "127.0.0.1" |
control_port | None (uses Tor’s default) |
control_socket | "/var/run/tor/control" |
tor_path | "tor" |
§Example
use stem_rs::interpreter::arguments::Arguments;
// Use defaults
let defaults = Arguments::default();
assert_eq!(defaults.control_address, "127.0.0.1");
// Parse from command line
let args = Arguments::parse(&["--interface".to_string(), "192.168.1.1:9051".to_string()]).unwrap();
assert_eq!(args.control_address, "192.168.1.1");
assert_eq!(args.control_port, Some(9051));Fields§
§control_address: StringIP address for the control interface.
Defaults to "127.0.0.1" (localhost).
control_port: Option<u16>Port number for the control interface.
If None, the default Tor control port is used.
user_provided_port: boolWhether the user explicitly specified a port.
Used to determine connection priority when both port and socket are available.
control_socket: StringPath to the Unix domain socket for control connection.
Defaults to "/var/run/tor/control".
user_provided_socket: boolWhether the user explicitly specified a socket path.
Used to determine connection priority when both port and socket are available.
tor_path: StringPath to the Tor binary.
Used when Tor needs to be started automatically.
Defaults to "tor" (found via PATH).
run_cmd: Option<String>Single command to execute and exit.
If set, the interpreter runs this command and exits instead of entering interactive mode.
run_path: Option<String>Path to a script file to execute.
If set, the interpreter runs all commands in the file and exits.
Takes precedence over run_cmd if the path exists.
disable_color: boolWhether to disable colored output.
When true, all output is plain text without ANSI color codes.
print_help: boolWhether to print help and exit.
When true, the interpreter prints usage information and exits
without connecting to Tor.
Implementations§
Source§impl Arguments
impl Arguments
Sourcepub fn parse(argv: &[String]) -> Result<Self, String>
pub fn parse(argv: &[String]) -> Result<Self, String>
Parses command-line arguments into an Arguments struct.
§Arguments
argv- Slice of command-line argument strings (excluding program name)
§Returns
Parsed arguments on success, or an error message on failure.
§Errors
Returns an error string if:
- An argument requires a value but none is provided
- An IP address is invalid
- A port number is invalid (not 1-65535)
- An unrecognized argument is provided
§Example
use stem_rs::interpreter::arguments::Arguments;
// Parse port only
let args = Arguments::parse(&["-i".to_string(), "9051".to_string()]).unwrap();
assert_eq!(args.control_port, Some(9051));
// Parse address and port
let args = Arguments::parse(&["-i".to_string(), "192.168.1.1:9051".to_string()]).unwrap();
assert_eq!(args.control_address, "192.168.1.1");
assert_eq!(args.control_port, Some(9051));
// Invalid port returns error
let result = Arguments::parse(&["-i".to_string(), "99999".to_string()]);
assert!(result.is_err());Sourcepub fn get_help() -> String
pub fn get_help() -> String
Returns the help message for command-line usage.
The help message includes all available options with their descriptions and default values.
§Example
use stem_rs::interpreter::arguments::Arguments;
let help = Arguments::get_help();
assert!(help.contains("--interface"));
assert!(help.contains("--socket"));
assert!(help.contains("--help"));