diff --git a/config/config.rush b/config/config.rush index f0954fe..e662093 100644 --- a/config/config.rush +++ b/config/config.rush @@ -1,4 +1,4 @@ -truncation-factor: false +truncation: false multiline-prompt: true history-limit: false show-errors: true diff --git a/src/exec/builtins/args.rs b/src/exec/builtins/args.rs index 803bf6f..4170f86 100644 --- a/src/exec/builtins/args.rs +++ b/src/exec/builtins/args.rs @@ -22,13 +22,15 @@ pub struct WorkingDirectoryArgs {} #[derive(Parser, Debug)] pub struct ChangeDirectoryArgs { + #[arg(help = "The path of the directory to switch to")] pub path: PathBuf, } #[derive(Parser, Debug)] pub struct ListDirectoryArgs { - #[arg(short = 'a', long = "all")] + #[arg(short = 'a', long = "all", help = "Show hidden files and directories")] pub show_hidden: bool, + #[arg(help = "The path of the directory to read")] pub path: Option, } @@ -43,66 +45,82 @@ pub struct ClearTerminalArgs {} #[derive(Parser, Debug)] pub struct MakeFileArgs { + #[arg(help = "The path of the file to create")] pub path: PathBuf, } #[derive(Parser, Debug)] pub struct MakeDirectoryArgs { + #[arg(help = "The path of the directory to create")] pub path: PathBuf, } #[derive(Parser, Debug)] pub struct DeleteFileArgs { + #[arg(help = "The path of the file to delete")] pub path: PathBuf, } #[derive(Parser, Debug)] pub struct ReadFileArgs { + #[arg(help = "The path of the file to read")] pub path: PathBuf, } #[derive(Parser, Debug)] pub struct RunExecutableArgs { + #[arg(help = "The path to the executable")] pub path: PathBuf, + #[arg(help = "The arguments to pass to the executable")] pub arguments: Vec, } #[derive(Parser, Debug)] +#[command(arg_required_else_help = true)] pub struct ConfigureArgs { - #[arg(long = "truncation-factor")] - pub truncation_factor: Option, - #[arg(long = "history-limit")] + #[arg( + long = "truncation", + help = "The number of characters to trim each directory name to in the prompt" + )] + pub truncation: Option, + #[arg( + long = "history-limit", + help = "The maximum number of commands to store in the history" + )] pub history_limit: Option, - #[arg(long = "multiline-prompt")] - pub multiline_prompt: Option, - #[arg(long = "show-errors")] - pub show_errors: Option, + #[arg( + long = "multiline-prompt", + help = "Whether to display the prompt on multiple lines" + )] + pub multiline_prompt: Option, + #[arg(long = "show-errors", help = "Whether to display error messages")] + pub show_errors: Option, } #[derive(Debug, Clone)] -pub enum FancyBool { +pub enum Bool { True, False, } -impl FromStr for FancyBool { +impl FromStr for Bool { type Err = String; fn from_str(s: &str) -> Result { if TRUE_ARGS.contains(&s) { - Ok(FancyBool::True) + Ok(Bool::True) } else if FALSE_ARGS.contains(&s) { - Ok(FancyBool::False) + Ok(Bool::False) } else { Err("invalid boolean value".to_owned()) } } } -impl From for bool { - fn from(b: FancyBool) -> Self { +impl From for bool { + fn from(b: Bool) -> Self { match b { - FancyBool::True => true, - FancyBool::False => false, + Bool::True => true, + Bool::False => false, } } } @@ -137,6 +155,7 @@ impl From for Option { #[derive(Parser, Debug)] pub struct EnvironmentVariableArgs { + #[arg(help = "The environment variable to display")] pub variable: EnvVariable, } @@ -166,21 +185,26 @@ pub enum EditPathSubcommand { #[derive(Args, Debug, Clone)] pub struct AppendPathCommand { + #[arg(help = "The path to append to the PATH variable")] pub path: PathBuf, } #[derive(Args, Debug, Clone)] pub struct PrependPathCommand { + #[arg(help = "The path to prepend to the PATH variable")] pub path: PathBuf, } #[derive(Args, Debug, Clone)] pub struct InsertPathCommand { + #[arg(help = "The index to insert the provided path at")] pub index: usize, + #[arg(help = "The path to insert into the PATH variable")] pub path: PathBuf, } #[derive(Args, Debug, Clone)] pub struct DeletePathCommand { + #[arg(help = "The index of the path to delete from the PATH variable")] pub index: usize, } diff --git a/src/exec/builtins/functions.rs b/src/exec/builtins/functions.rs index a006914..7f56856 100644 --- a/src/exec/builtins/functions.rs +++ b/src/exec/builtins/functions.rs @@ -193,8 +193,8 @@ pub fn run_executable(shell: &mut ShellState, args: Vec<&str>) -> Result<()> { pub fn configure(shell: &mut ShellState, args: Vec<&str>) -> Result<()> { let arguments = clap_handle!(ConfigureArgs::try_parse_from(args)); - if let Some(truncation_factor) = arguments.truncation_factor { - shell.config.truncation_factor = truncation_factor.into(); + if let Some(truncation) = arguments.truncation { + shell.config.truncation = truncation.into(); } if let Some(history_limit) = arguments.history_limit { diff --git a/src/state/config.rs b/src/state/config.rs index 8bd85db..e02711c 100644 --- a/src/state/config.rs +++ b/src/state/config.rs @@ -10,7 +10,7 @@ use crate::errors::{Handle, Result}; /// Represents any settings for the shell, most of which can be configured by the user pub struct Configuration { /// The truncation length for the prompt - pub truncation_factor: Option, + pub truncation: Option, /// How many directories to store in the back/forward history pub history_limit: Option, /// Whether to show the prompt tick on a new line @@ -24,7 +24,7 @@ pub struct Configuration { impl Default for Configuration { fn default() -> Self { Self { - truncation_factor: None, + truncation: None, history_limit: None, multiline_prompt: false, show_errors: true, @@ -61,11 +61,11 @@ impl Configuration { // ? Should these be underscores instead of hyphens? match key { - "truncation-factor" => { + "truncation" => { if let Ok(length) = value.parse::() { - config.truncation_factor = Some(length); + config.truncation = Some(length); } else if value == "false" { - config.truncation_factor = None; + config.truncation = None; } else { return Err( file_err!(CouldNotReadFile: filename).set_context(&read_error_msg) diff --git a/src/state/path.rs b/src/state/path.rs index 6a213c0..e9692ab 100644 --- a/src/state/path.rs +++ b/src/state/path.rs @@ -85,7 +85,7 @@ impl Path { /// Gets the shortened version of the path /// If a truncation factor is provided, the path will be truncated /// The shortened path will always have the home directory collapsed - pub fn collapse(&self, home_directory: &PathBuf, truncation_factor: Option) -> String { + pub fn collapse(&self, home_directory: &PathBuf, truncation: Option) -> String { // ? Is there a less redundant way to write this? let path = match self.absolute_path.strip_prefix(home_directory) { Ok(path) => { @@ -105,11 +105,11 @@ impl Path { let directories: Vec = path.split('/').map(|d| d.to_string()).collect(); let mut truncated_directories = Vec::new(); - if let Some(factor) = truncation_factor { + if let Some(trunctation) = truncation { for dir in directories { let mut truncated_dir = dir.clone(); - if dir.len() > factor { - truncated_dir.truncate(factor); + if dir.len() > trunctation { + truncated_dir.truncate(trunctation); } truncated_directories.push(truncated_dir); diff --git a/src/state/shell.rs b/src/state/shell.rs index 41442ef..f625479 100644 --- a/src/state/shell.rs +++ b/src/state/shell.rs @@ -31,7 +31,7 @@ impl ShellState { pub fn generate_prompt(&self) -> String { let user = self.environment.USER.clone(); let home = &self.environment.HOME; - let truncation = self.config.truncation_factor; + let truncation = self.config.truncation; let cwd = self.environment.CWD.collapse(home, truncation); let prompt_delimiter = match self.config.multiline_prompt { true => "\n",