ShellOptions

Struct ShellOptions 

Source
pub struct ShellOptions {
    pub errexit: bool,
    pub nounset: bool,
    pub xtrace: bool,
    pub verbose: bool,
    pub noexec: bool,
    pub noglob: bool,
    pub noclobber: bool,
    pub allexport: bool,
    pub notify: bool,
    pub ignoreeof: bool,
    pub monitor: bool,
}
Expand description

Shell option flags that control shell behavior

This struct contains boolean flags for all supported shell options. Each option can be accessed directly or through the getter/setter methods that support both short and long option names.

Fields§

§errexit: bool

-e: Exit on command failure

§nounset: bool

-u: Treat unset variables as error

§xtrace: bool

-x: Print commands before execution

§verbose: bool

-v: Print input lines as read

§noexec: bool

-n: Read but don’t execute commands

§noglob: bool

-f: Disable pathname expansion

§noclobber: bool

-C: Prevent overwriting files with redirection

§allexport: bool

-a: Auto-export all variables

§notify: bool

-b: Notify of job completion immediately

§ignoreeof: bool

Ignore EOF (Ctrl+D) - not a standard POSIX option but commonly supported

§monitor: bool

-m: Enable job control (monitor)

Implementations§

Source§

impl ShellOptions

Source

pub fn get_by_short_name(&self, name: char) -> Option<bool>

Retrieve the value of a shell option by its short-name flag.

Returns Some(bool) with the option’s current value for recognized short names; None if the short name is not recognized.

§Examples
use rush_sh::state::ShellOptions;
let opts = ShellOptions::default();
assert_eq!(opts.get_by_short_name('e'), Some(false)); // errexit is false by default
assert_eq!(opts.get_by_short_name('?'), None); // unknown short name
Source

pub fn set_by_short_name( &mut self, name: char, value: bool, ) -> Result<(), String>

Set a shell option identified by its single-character short name.

Sets the option corresponding to name to value. Recognized short names: ‘e’ (errexit), ‘u’ (nounset), ‘x’ (xtrace), ‘v’ (verbose), ‘n’ (noexec), ‘f’ (noglob), ‘C’ (noclobber), ‘a’ (allexport), ‘b’ (notify), ‘m’ (monitor).

§Arguments
  • name - single-character short option name.
  • value - true to enable the option, false to disable it.
§Returns

Ok(()) on success, or Err(String) if name is not a recognized option.

§Examples
use rush_sh::state::ShellOptions;
let mut opts = ShellOptions::default();
opts.set_by_short_name('e', true).unwrap();
assert!(opts.errexit);
Source

pub fn get_by_long_name(&self, name: &str) -> Option<bool>

Retrieve the value of a shell option by its long name.

name is the option’s full identifier (for example: “errexit”, “nounset”, “xtrace”).

§Returns

Some(true) if the option is enabled, Some(false) if the option is disabled, or None if the name is not recognized.

§Examples
use rush_sh::state::ShellOptions;
let mut opts = ShellOptions::default();
opts.errexit = true;
assert_eq!(opts.get_by_long_name("errexit"), Some(true));
assert_eq!(opts.get_by_long_name("noglob"), Some(false));
assert_eq!(opts.get_by_long_name("unknown"), None);
Source

pub fn set_by_long_name( &mut self, name: &str, value: bool, ) -> Result<(), String>

Set a shell option by its long name.

Sets the specified long-form option (for example "errexit" or "nounset") to the provided boolean value. Returns Ok(()) if the option was recognized and set, or Err(String) if the name is not recognized.

§Examples
use rush_sh::state::ShellOptions;
let mut opts = ShellOptions::default();
opts.set_by_long_name("errexit", true).unwrap();
assert!(opts.errexit);

assert!(opts.set_by_long_name("nonexistent", true).is_err());
Source

pub fn get_all_options(&self) -> Vec<(&'static str, char, bool)>

Lists all shell option names with their short-letter aliases and current values.

Returns a vector of tuples (long_name, short_name, value) for every supported option. The short_name is '\0' when no short alias exists.

§Examples
use rush_sh::state::ShellOptions;
let opts = ShellOptions::default();
let all = opts.get_all_options();
assert!(all.iter().any(|(name, _, _)| *name == "errexit"));
assert!(all.iter().any(|(name, short, _)| *name == "ignoreeof" && *short == '\0'));

Trait Implementations§

Source§

impl Clone for ShellOptions

Source§

fn clone(&self) -> ShellOptions

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 ShellOptions

Source§

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

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

impl Default for ShellOptions

Source§

fn default() -> Self

Create a ShellOptions with all option flags set to false.

§Examples
use rush_sh::state::ShellOptions;
let opts = ShellOptions::default();
assert!(!opts.errexit && !opts.nounset && !opts.xtrace);

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> 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.