From 98580f3a7ffc8e6880e8028dec634ec426935634 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 23 May 2023 17:31:17 +0200 Subject: [PATCH] Updates readme --- src/actions.rs | 3 ++- src/errors.rs | 18 +++++++++--------- src/main.rs | 23 +++++++++++++---------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index 4066e97..5531f13 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -42,7 +42,8 @@ pub fn execute_parsed_cli(cli: Cli) -> Result<(), errors::SnippetError> { if let Some(e) = e.source() { println!("This error was caused by: \n\t{}", e); } - return Err(e); + // return Err(e); + return Ok(()); // Very unconvinced by this }; } Ok(()) diff --git a/src/errors.rs b/src/errors.rs index 72d62da..d1c0d41 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -31,30 +31,30 @@ pub enum SnippetError { impl fmt::Display for SnippetError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - SnippetError::Unknown => write!(f, "An unknonw error occured"), - SnippetError::ClapError(..) => write!(f, "An error occured while parsing the input"), - SnippetError::IOError(..) => write!(f, "An error occured while editing the file"), + SnippetError::Unknown => write!(f, "An unknonw error occured."), + SnippetError::ClapError(..) => write!(f, "An error occured while parsing the input."), + SnippetError::IOError(..) => write!(f, "An error occured while editing the file."), SnippetError::YAMLError(..) => { - write!(f, "Couldn't convert the given arguments into a yaml") + write!(f, "Couldn't convert the given arguments into a yaml.") } SnippetError::NotFound(ref p) => write!( f, - "The file {:?} doesn't exists",p.file_name().unwrap(), + "The Snippet {:?} doesn't exists. Use -c to create it and/or -E to edit it.",p.file_name().unwrap(), ), SnippetError::NotFoundNoRetryError(ref p) => { write!( f, - "The config {:?} doen't exists. Use -c to create it.", + "The Snippet {:?} doen't exists. Use -c to create it.", p.file_name(), ) } SnippetError::FoundNoEraseError(ref p) => write!( f, - "The snippet {:?} already exists. Use -f/--force to overwrite it.", + "The Snippet {:?} already exists. Use -f/--force to overwrite it.", p.file_name().unwrap(), ), - SnippetError::ReparsingError => write!(f,"The snipped couldn't be re-parsed, it might be caused by a bad value in your edit. \nThe snipped was saved as a raw file instead but cant be used as is."), - SnippetError::IndexError(ref i) => write!(f,"An error occured while trying to access the index {} of the given arguments.\nThe default arguments for this command likely do not support {} arguments",i,i+1), + SnippetError::ReparsingError => write!(f,"The Snippet couldn't be re-parsed, it might be caused by a bad value in your edit. \nThe snipped was saved as a raw file instead but cant be used as is."), + SnippetError::IndexError(ref i) => write!(f,"An error occured while trying to access the index {} of the given arguments.\nThe default arguments for this command likely do not support {} arguments.",i,i+1), } } } diff --git a/src/main.rs b/src/main.rs index b07f945..652c2f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,23 +11,27 @@ mod snippet; mod tokenizer; mod wrapper_functions; -/// The cli arguments to give to the utility +/// SNP an utility to create and manage Snippets of code +/// +/// Use "snp -c -E snippet_name" to create a new Snippet and start editing it and "snp snippet_name argument" to use it +/// You can use "{}" or "{0}" in your Snippet to later format it to your needs as would python .format() or rust format!("",) work +/// Doing so will need as many default arguments to fill the command than the total count of {} #[derive(Parser, Debug)] -#[command(author, version, about)] +#[command(author, version, about, verbatim_doc_comment)] pub struct Cli { - /// The snippet name (and therefore his path) + /// The Snippet name (and therefore his path) #[arg()] snippet: String, - /// Wether to try to load or instead create a new one + /// Try to create a Snippet with the given name and default arguments #[arg(short, long, default_value_t = false)] create: bool, - /// Show where the snippet is located + /// Show where the Snippet is located #[arg(short, long, default_value_t = false)] locate: bool, - /// Launch the editor and edit the snippet + /// Launch the editor and edit the Snippet content #[arg(short, long, default_value_t = false)] edit: bool, @@ -37,18 +41,17 @@ pub struct Cli { /// The list of arguments to give to the snippet /// if the -c flag is used, it's used to create the default arguments - #[arg(help = "List of args to give to the snipplet")] args: Vec, - /// Wether to force the creation or save and overwrite existing data + /// Force the creation/moving/renaming of a Snippet even if it mean overwriting an existing one #[arg(short, long, default_value_t = false)] force: bool, - /// Wether to delete a snippet, takes precedence over everything + /// Delete a snippet, takes precedence over everything #[arg(short, long, default_value_t = false)] delete: bool, - /// Wether to rename the snippet + /// Try to rename the Snippet (Use -f if the destination name already exist) #[arg(short, long)] rename: Option, }