Arguments

Struct Arguments 

Source
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

FieldDefault
control_address"127.0.0.1"
control_portNone (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: String

IP 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: bool

Whether the user explicitly specified a port.

Used to determine connection priority when both port and socket are available.

§control_socket: String

Path to the Unix domain socket for control connection.

Defaults to "/var/run/tor/control".

§user_provided_socket: bool

Whether the user explicitly specified a socket path.

Used to determine connection priority when both port and socket are available.

§tor_path: String

Path 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: bool

Whether to disable colored output.

When true, all output is plain text without ANSI color codes.

§print_help: bool

Whether to print help and exit.

When true, the interpreter prints usage information and exits without connecting to Tor.

Implementations§

Source§

impl Arguments

Source

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());
Source

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"));

Trait Implementations§

Source§

impl Clone for Arguments

Source§

fn clone(&self) -> Arguments

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Arguments

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Arguments

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.