Updates readme
This commit is contained in:
parent
de6a5182a1
commit
98580f3a7f
|
|
@ -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(())
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
src/main.rs
23
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<String>,
|
||||
|
||||
/// 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<String>,
|
||||
}
|
||||
|
|
|
|||
Reference in New Issue