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: boolIgnore EOF (Ctrl+D) - not a standard POSIX option but commonly supported
monitor: bool-m: Enable job control (monitor)
Implementations§
Source§impl ShellOptions
impl ShellOptions
Sourcepub fn get_by_short_name(&self, name: char) -> Option<bool>
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 nameSourcepub fn set_by_short_name(
&mut self,
name: char,
value: bool,
) -> Result<(), String>
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);Sourcepub fn get_by_long_name(&self, name: &str) -> Option<bool>
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);Sourcepub fn set_by_long_name(
&mut self,
name: &str,
value: bool,
) -> Result<(), String>
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());Sourcepub fn get_all_options(&self) -> Vec<(&'static str, char, bool)>
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
impl Clone for ShellOptions
Source§fn clone(&self) -> ShellOptions
fn clone(&self) -> ShellOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more