From 2c48bbd4e725090e65f0ee9ea43d3a9d903730e0 Mon Sep 17 00:00:00 2001 From: beffroi Date: Wed, 24 May 2023 11:56:42 +0200 Subject: [PATCH 1/8] Corrects bugs on no args and doc not showing fully --- TODO.md | 10 +++++++++- src/main.rs | 1 - src/wrapper_functions.rs | 9 ++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index 67a3aac..f4b8ac7 100644 --- a/TODO.md +++ b/TODO.md @@ -7,7 +7,15 @@ [ ] Double backslash win [ ] Remove last return [ ] Remove the prerequiste of name for --list - + [ ] Add some examples with --example + [ ] Double backslash windows + [ ] Case sensitivity windows + [ ] Bigger message for print "The snippet name ca be found at "i + [ ] Message on delete + [ ] Investigate clap on -rfe etc + [ ] Better message on no errase + [ ] Edit -> edit-all + ### Currently working on ## Finished diff --git a/src/main.rs b/src/main.rs index af8c9cb..d91dc76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,6 @@ mod tokenizer; mod wrapper_functions; /// 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 {} diff --git a/src/wrapper_functions.rs b/src/wrapper_functions.rs index f82254e..8036b43 100644 --- a/src/wrapper_functions.rs +++ b/src/wrapper_functions.rs @@ -3,6 +3,7 @@ //! All functions included should either take a Cli object and return a SnippetError //! or be a helper function for such a function +use clap::CommandFactory; #[allow(unused)] // Mandatory because of how test and rust-analyser work use edit::edit; @@ -224,7 +225,13 @@ pub fn list_snippets(_cli: &Cli) -> Result<(), SnippetError> { /// Print the snippet to stdout pub fn print_snippet(cli: &Cli) -> Result<(), SnippetError> { - // Try to load the snippet + // Try to load the snippet i + if let None = cli.snippet { + // This wonky hack exists because of subcommands + // It could also be checked when populating, but is way easier this + Cli::command().print_long_help()?; + return Ok(()); + } let (_, f) = match check_dir_and_open(cli.snippet.as_ref().unwrap())? { FileStatus::Opened((p, f)) => (p, f), FileStatus::NotFound(p) => return Err(SnippetError::NotFound(p)), From cb2c71112902d3156bade93064b6dc9b729d7552 Mon Sep 17 00:00:00 2001 From: beffroi Date: Wed, 24 May 2023 15:19:49 +0200 Subject: [PATCH 2/8] Adds ore messages --- TODO.md | 20 ++++++++++---------- src/actions.rs | 3 ++- src/main.rs | 2 +- src/wrapper_functions.rs | 13 ++++++++++--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/TODO.md b/TODO.md index f4b8ac7..9392d71 100644 --- a/TODO.md +++ b/TODO.md @@ -1,27 +1,27 @@ ## TODO [ ] Benchmarks [ ] Better use of file modes - [ ] Document non coverage [ ] Find a solution for the .badpocalypse [ ] Edit args only - [ ] Double backslash win - [ ] Remove last return - [ ] Remove the prerequiste of name for --list - [ ] Add some examples with --example [ ] Double backslash windows [ ] Case sensitivity windows - [ ] Bigger message for print "The snippet name ca be found at "i - [ ] Message on delete - [ ] Investigate clap on -rfe etc - [ ] Better message on no errase - [ ] Edit -> edit-all + [ ] Bigger message for print "The snippet name can be found at " + [ ] Use Ok for results instead of prints ### Currently working on + [ ] Add some examples with --example ## Finished + [*] Edit -> edit-all + [*] Message on delete + [*] Remove last return + [*] Remove the prerequiste of name for --list + [*] Better message on no erase + [*] Comment on no op with replace ## Posponed or rendered useless [x] Chain the methods when possible with result ? [ ] Make a lib for dynamic_format and snippets (impl make a trait for have .id() and other future t) [ ] Change all uncatchables errors to expect to be more helpful or change them to better errors + [ ] Document non coverage diff --git a/src/actions.rs b/src/actions.rs index 9ee4d72..8dbca37 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -138,7 +138,8 @@ mod test { vec![Actions::Create] ), (false_cli!("snp", "-l"), vec![Actions::List]), - // (false_cli!("snp", "-l"), vec![Actions::List]), + (false_cli!("snp"), vec![Actions::Show]), // It's an acceptable error + // (false_cli!("snp", "-l"), vec![Actions::List]), ); for (cli, res) in group.iter() { println!("Testing {:?}..actions expected {:?}", cli, res); diff --git a/src/main.rs b/src/main.rs index d91dc76..391209d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ pub struct Cli { /// Launch the editor and edit the whole snippet #[arg( short = 'E', - long = "Edit", + long = "edit-all", default_value_t = false, requires = "mandatory" )] diff --git a/src/wrapper_functions.rs b/src/wrapper_functions.rs index 8036b43..fc555bf 100644 --- a/src/wrapper_functions.rs +++ b/src/wrapper_functions.rs @@ -8,7 +8,7 @@ use clap::CommandFactory; use edit::edit; use std::fs::{self, create_dir_all}; -use std::io::{read_to_string, Write}; +use std::io::{self, read_to_string, Write}; use std::{env, fs::File, path::PathBuf}; use crate::errors::SnippetError; @@ -60,6 +60,7 @@ pub fn rename_snippet(cli: &Cli) -> Result<(), SnippetError> { // Check wether the snippet exitsts let new_name = cli.rename.as_ref().unwrap(); if new_name == cli.snippet.as_ref().unwrap() { + println!("The original and new snippet name are the same, skipping..."); return Ok(()); // The noop is a success ? } let (f, oldpath) = match check_dir_and_open(cli.snippet.as_ref().unwrap())? { @@ -245,7 +246,8 @@ pub fn print_snippet(cli: &Cli) -> Result<(), SnippetError> { // Print the snippet let f_str = dynamic_formatter::dynamic_format(&snp.content, final_args)?; - println!("{}", f_str); + print!("{}", f_str); + io::stdout().flush()?; Ok(()) } @@ -253,7 +255,12 @@ pub fn print_snippet(cli: &Cli) -> Result<(), SnippetError> { pub fn delete_snippet(cli: &Cli) -> Result<(), SnippetError> { let mut path = config_folder()?; path.push(format!("{}.yaml", cli.snippet.as_ref().unwrap())); - std::fs::remove_file(path)?; + std::fs::remove_file(&path)?; + println!( + "The snippet \"{}\" was successfully deleted.", + // path.file_name().unwrap().to_str().unwrap() + cli.snippet.as_ref().unwrap() + ); Ok(()) } /// The status of the request after the path was attempted to be opened From 88c0506f6afd85e4230df2c962fd4a86319ae0c8 Mon Sep 17 00:00:00 2001 From: beffroi Date: Wed, 24 May 2023 16:11:18 +0200 Subject: [PATCH 3/8] Updates the todo --- TODO.md | 1 + src/actions.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 9392d71..e2f27e3 100644 --- a/TODO.md +++ b/TODO.md @@ -10,6 +10,7 @@ ### Currently working on [ ] Add some examples with --example + [ ] Error: Delete, unclear ## Finished [*] Edit -> edit-all diff --git a/src/actions.rs b/src/actions.rs index 8dbca37..0dc7fd0 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -39,7 +39,7 @@ pub fn execute_parsed_cli(cli: Cli) -> Result<(), errors::SnippetError> { Actions::Rename => wrapper_functions::rename_snippet(&cli), Actions::List => wrapper_functions::list_snippets(&cli), } { - // println!("An error occured during runtime:\n\t{}", e); + println!("An error occured during runtime:\n\t{}", e); // if let Some(e) = e.source() { // println!("This error was caused by: \n\t{}", e); // } From d2f767abc8f7ce6bdcdd76c7b581d15bba6348f2 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 24 May 2023 20:08:01 +0200 Subject: [PATCH 4/8] Corrects several windows bugs and bad names --- TODO.md | 15 +++++---- src/actions.rs | 28 +++++++++++------ src/main.rs | 20 +++++++++--- src/wrapper_functions.rs | 68 ++++++++++++++++++++++++++++++++++------ 4 files changed, 100 insertions(+), 31 deletions(-) diff --git a/TODO.md b/TODO.md index e2f27e3..bda2bd8 100644 --- a/TODO.md +++ b/TODO.md @@ -3,14 +3,15 @@ [ ] Better use of file modes [ ] Find a solution for the .badpocalypse [ ] Edit args only - [ ] Double backslash windows [ ] Case sensitivity windows - [ ] Bigger message for print "The snippet name can be found at " [ ] Use Ok for results instead of prints - + [ ] Use priority instead of a cursed match statement + [ ] Correct the newline problem (with toml ?) + [ ] Have a method to get name, path and all with a custom error on unwrap + ### Currently working on - [ ] Add some examples with --example - [ ] Error: Delete, unclear + [-] Add some examples with --example + [ ] Have an actual human give feedback on the error name readability ## Finished [*] Edit -> edit-all @@ -19,10 +20,12 @@ [*] Remove the prerequiste of name for --list [*] Better message on no erase [*] Comment on no op with replace + [*] Add example to the tests on actions, wrapper_functions + [*] Double backslash windows ## Posponed or rendered useless [x] Chain the methods when possible with result ? [ ] Make a lib for dynamic_format and snippets (impl make a trait for have .id() and other future t) [ ] Change all uncatchables errors to expect to be more helpful or change them to better errors [ ] Document non coverage - + [*] Error: Delete, unclear ? \ No newline at end of file diff --git a/src/actions.rs b/src/actions.rs index 0dc7fd0..0052612 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -23,6 +23,8 @@ pub enum Actions { Rename, /// Find a snippet matching a name/regex Find, + /// Create an example snippet + Example, } /// The main worker, execute all commands given as Args @@ -38,6 +40,7 @@ pub fn execute_parsed_cli(cli: Cli) -> Result<(), errors::SnippetError> { Actions::Delete => wrapper_functions::delete_snippet(&cli), Actions::Rename => wrapper_functions::rename_snippet(&cli), Actions::List => wrapper_functions::list_snippets(&cli), + Actions::Example => wrapper_functions::create_example(&cli), } { println!("An error occured during runtime:\n\t{}", e); // if let Some(e) = e.source() { @@ -62,17 +65,19 @@ fn populate_actions(cli: &Cli) -> Vec { cli.delete, &cli.rename, cli.list, + cli.example, ) { - (true, _, _, _, false, _, false) => actions.push(Actions::Find), - (_, false, false, true, false, _, false) => actions.push(Actions::EditAll), - (_, true, _, true, false, _, false) => actions.push(Actions::EditAll), - (_, true, false, false, false, _, false) => actions.push(Actions::Create), - (_, false, true, _, false, _, false) => actions.push(Actions::Edit), - (_, true, true, false, false, _, false) => actions.push(Actions::Edit), - (false, false, false, false, false, None, false) => actions.push(Actions::Show), - (_, _, _, _, true, _, false) => actions.push(Actions::Delete), - (_, _, _, _, _, Some(_), false) => actions.push(Actions::Rename), - (_, _, _, _, _, _, true) => actions.push(Actions::List), + (true, _, _, _, false, _, false, false) => actions.push(Actions::Find), + (_, false, false, true, false, _, false, false) => actions.push(Actions::EditAll), + (_, true, _, true, false, _, false, false) => actions.push(Actions::EditAll), + (_, true, false, false, false, _, false, false) => actions.push(Actions::Create), + (_, false, true, _, false, _, false, false) => actions.push(Actions::Edit), + (_, true, true, false, false, _, false, false) => actions.push(Actions::Edit), + (false, false, false, false, false, None, false, false) => actions.push(Actions::Show), + (_, _, _, _, true, _, false, false) => actions.push(Actions::Delete), + (_, _, _, _, _, Some(_), false, false) => actions.push(Actions::Rename), + (_, _, _, _, _, _, true, false) => actions.push(Actions::List), + (_, _, _, _, _, _, _, true) => actions.push(Actions::Example), } actions } @@ -138,6 +143,7 @@ mod test { vec![Actions::Create] ), (false_cli!("snp", "-l"), vec![Actions::List]), + (false_cli!("snp", "--example"), vec![Actions::Example]), (false_cli!("snp"), vec![Actions::Show]), // It's an acceptable error // (false_cli!("snp", "-l"), vec![Actions::List]), ); @@ -162,6 +168,8 @@ mod test { false_cli!("snp", "parsed_cli", "-r", "new_name", "-f"), false_cli!("snp", "new_name", "-d"), false_cli!("snp", "-l"), + false_cli!("snp"), + false_cli!("snp", "--example"), ]; let bad_cli = vec![ diff --git a/src/main.rs b/src/main.rs index 391209d..b60b65b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,16 @@ mod tokenizer; mod wrapper_functions; /// 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 {} +/// - +/// Use "snp -c -E snippet_name" to create a new Snippet and +/// directly start editing it, then use"snp snippet_name" 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 {} +/// - +/// You can get a working example with --example witch will guide you +/// through all the basic steps for snippet creation and edition #[derive(Parser, Debug)] #[command(author, version, about, verbatim_doc_comment)] pub struct Cli { @@ -43,8 +50,7 @@ pub struct Cli { )] edit_all: bool, - /// The list of arguments to give to the snippet - /// if the -c flag is used, it's used to create the default arguments + /// The list of arguments to give to the snippet or the snippet creator #[arg(requires = "mandatory")] args: Vec, @@ -63,6 +69,10 @@ pub struct Cli { /// List all snippets in the snippet folder #[arg(short, long, default_value_t = false, group = "mutex")] list: bool, + + /// Create an example snippet named example with some basic documentation + #[arg(long, default_value_t = false, group = "mutex")] + example: bool, } /// Main entry point, everything is defered for testing and coverage diff --git a/src/wrapper_functions.rs b/src/wrapper_functions.rs index fc555bf..90d19e7 100644 --- a/src/wrapper_functions.rs +++ b/src/wrapper_functions.rs @@ -22,7 +22,11 @@ pub fn locate_snippet(cli: &Cli) -> Result<(), SnippetError> { let status = check_dir_and_open(cli.snippet.as_ref().unwrap())?; match status { FileStatus::Opened((p, _)) => { - println!("{:?}", p.as_os_str()); + println!( + "The snippet {} is located at \"{}\"", + cli.snippet.as_ref().unwrap(), + p.as_os_str().to_str().unwrap() + ); Ok(()) } FileStatus::NotFound(p) => Err(SnippetError::NotFoundNoRetryError(p)), @@ -51,7 +55,10 @@ pub fn create_snippet(cli: &Cli) -> Result<(), SnippetError> { FileStatus::NotFound(p) => (File::create(&p)?, p), // Create a new snippet }; snp.save_in(&f)?; - println!("The snippet {:?} was created successfully", p); + println!( + "The snippet {} was created successfully", + p.as_os_str().to_str().unwrap() + ); Ok(()) } @@ -124,8 +131,8 @@ pub fn edit_snippet(cli: &Cli) -> Result<(), SnippetError> { snp.write_over(&p)?; println!( - "The snippet {:?} was succesfully saved", - p.file_name().unwrap() + "The snippet {} was succesfully saved", + p.file_name().unwrap().to_str().unwrap() ); Ok(()) } @@ -161,8 +168,8 @@ pub fn edit_whole_snippet(cli: &Cli) -> Result<(), SnippetError> { // No renaming has occured, the file can safely be overriten snp.write_over(&origin_p)?; println!( - "The snippet {:?} was succesfully saved", - origin_p.file_name().unwrap() + "The snippet {} was succesfully saved", + origin_p.file_name().unwrap().to_str().unwrap() ); Ok(()) } else { @@ -183,7 +190,10 @@ pub fn edit_whole_snippet(cli: &Cli) -> Result<(), SnippetError> { FileStatus::NotFound(p) => (File::create(&p)?, p), }; snp.save_in(&dest_f)?; - println!("The snippet was successfuly saved in {:?}", dest_p); + println!( + "The snippet was successfuly saved in {}", + dest_p.into_os_string().to_str().unwrap() + ); Ok(()) } } @@ -195,8 +205,8 @@ pub fn edit_whole_snippet(cli: &Cli) -> Result<(), SnippetError> { write!(failover, "{}", &buf)?; println!( - "The snippet was saved under {:?} in your config", - origin_p.file_name().unwrap() + "The snippet was saved under {} in your config", + origin_p.file_name().unwrap().to_str().unwrap() ); Err(SnippetError::ReparsingError) } @@ -227,9 +237,10 @@ pub fn list_snippets(_cli: &Cli) -> Result<(), SnippetError> { /// Print the snippet to stdout pub fn print_snippet(cli: &Cli) -> Result<(), SnippetError> { // Try to load the snippet i - if let None = cli.snippet { + if cli.snippet.is_none() { // This wonky hack exists because of subcommands // It could also be checked when populating, but is way easier this + #[cfg(not(feature = "test"))] Cli::command().print_long_help()?; return Ok(()); } @@ -263,6 +274,43 @@ pub fn delete_snippet(cli: &Cli) -> Result<(), SnippetError> { ); Ok(()) } + +/// Create an example snippet with a small guide and the next step printed out +pub fn create_example(_cli: &Cli) -> Result<(), SnippetError> { + let mut path = config_folder()?; + path.push("unique_example.yaml"); + println!( +"The snippet unique_example was created. You can use the following command to launch an editor and begin editing it: + $ snp unique_example -E + +Once you are done with the editing, you can try using the snippet with: + $ snp unique_example + +If you wish to delete the snippet, you can use the following command: + $ snp -d unique_example" + ); + let arguments = vec!["Argument 1", "Argument 2", "Foo", "Bar"]; + let text = "This is a snippet created as an example. +You can type several lines of code to help you in your daily coding process. +This snippet manager accepts either {} as a argument placeholder +and will fill it with Argument 1, the first argument. +You can also use {0} to have the first argument somewhere else. +Or {3} to skip to the last argument and finish with {} {} {} +If you only needed to edit this code part and not the snippet, +you can use instead `snp unique_example -e` (not -E). +Please consult the --help for the full list of commands ! +"; + let snp = Snippet::new( + "unique_example".to_string(), + arguments.iter().map(|s| s.to_string()).collect(), + text.to_string(), + ); + + _ = std::fs::remove_file(&path); + let f = File::create(path)?; + snp.save_in(&f)?; + Ok(()) +} /// The status of the request after the path was attempted to be opened pub enum FileStatus { /// The file was opened with success a tuple is returned From 86f5226c19252b06962f170482e6f86693304b6a Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 24 May 2023 20:10:01 +0200 Subject: [PATCH 5/8] Tests passing and bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0819a21..fa14dad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "snp" authors = ["Dandaedre"] -version = "1.0.4" +version = "1.0.5" edition = "2021" [features] From f62ac2fe3476ee47788b28e8ce1a60911ca0fbbb Mon Sep 17 00:00:00 2001 From: beffroi Date: Thu, 25 May 2023 16:58:32 +0200 Subject: [PATCH 6/8] Adds an extra line on the example message --- src/wrapper_functions.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wrapper_functions.rs b/src/wrapper_functions.rs index 90d19e7..ea6a735 100644 --- a/src/wrapper_functions.rs +++ b/src/wrapper_functions.rs @@ -280,12 +280,17 @@ pub fn create_example(_cli: &Cli) -> Result<(), SnippetError> { let mut path = config_folder()?; path.push("unique_example.yaml"); println!( -"The snippet unique_example was created. You can use the following command to launch an editor and begin editing it: - $ snp unique_example -E +"The snippet unique_example was created. You can use the following command to launch an editor and begin editing the content of the example: + $ snp unique_example -e + +Note that only the content of the text is editable in this mode, to edit the whole snippet use: + $ snp unique_example -E Once you are done with the editing, you can try using the snippet with: $ snp unique_example - +or + $ snp unique_example random parameters separated by spaces + If you wish to delete the snippet, you can use the following command: $ snp -d unique_example" ); From 63365ee5dc6656cf07fed01a60327919845bd00e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 25 May 2023 20:24:59 +0200 Subject: [PATCH 7/8] Added examples --- TODO.md | 12 ++---------- src/main.rs | 22 +++++++++++----------- src/wrapper_functions.rs | 26 +++++++++++++------------- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/TODO.md b/TODO.md index bda2bd8..fcc3252 100644 --- a/TODO.md +++ b/TODO.md @@ -6,26 +6,18 @@ [ ] Case sensitivity windows [ ] Use Ok for results instead of prints [ ] Use priority instead of a cursed match statement - [ ] Correct the newline problem (with toml ?) [ ] Have a method to get name, path and all with a custom error on unwrap ### Currently working on - [-] Add some examples with --example [ ] Have an actual human give feedback on the error name readability ## Finished - [*] Edit -> edit-all - [*] Message on delete - [*] Remove last return - [*] Remove the prerequiste of name for --list - [*] Better message on no erase - [*] Comment on no op with replace - [*] Add example to the tests on actions, wrapper_functions - [*] Double backslash windows + [*] Add some examples with --example ## Posponed or rendered useless [x] Chain the methods when possible with result ? [ ] Make a lib for dynamic_format and snippets (impl make a trait for have .id() and other future t) [ ] Change all uncatchables errors to expect to be more helpful or change them to better errors [ ] Document non coverage + [ ] Correct the newline problem (with toml ?) [*] Error: Delete, unclear ? \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b60b65b..3d86122 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,17 +11,17 @@ mod snippet; mod tokenizer; mod wrapper_functions; -/// SNP an utility to create and manage Snippets of code -/// - -/// Use "snp -c -E snippet_name" to create a new Snippet and -/// directly start editing it, then use"snp snippet_name" 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 {} -/// - -/// You can get a working example with --example witch will guide you -/// through all the basic steps for snippet creation and edition +/// SNP an utility to create and manage Snippets of code +/// _ +/// Use "snp -c -E snippet_name" to create a new Snippet and +/// directly start editing it, then use"snp snippet_name" 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 {} +/// - +/// You can get a working example with --example witch will guide you +/// through all the basic steps for snippet creation and edition #[derive(Parser, Debug)] #[command(author, version, about, verbatim_doc_comment)] pub struct Cli { diff --git a/src/wrapper_functions.rs b/src/wrapper_functions.rs index ea6a735..c87966b 100644 --- a/src/wrapper_functions.rs +++ b/src/wrapper_functions.rs @@ -281,30 +281,30 @@ pub fn create_example(_cli: &Cli) -> Result<(), SnippetError> { path.push("unique_example.yaml"); println!( "The snippet unique_example was created. You can use the following command to launch an editor and begin editing the content of the example: - $ snp unique_example -e +$ snp unique_example -e Note that only the content of the text is editable in this mode, to edit the whole snippet use: - $ snp unique_example -E +$ snp unique_example -E Once you are done with the editing, you can try using the snippet with: - $ snp unique_example +$ snp unique_example or - $ snp unique_example random parameters separated by spaces - +$ snp unique_example random parameters separated by spaces + If you wish to delete the snippet, you can use the following command: - $ snp -d unique_example" +$ snp -d unique_example" ); let arguments = vec!["Argument 1", "Argument 2", "Foo", "Bar"]; let text = "This is a snippet created as an example. You can type several lines of code to help you in your daily coding process. This snippet manager accepts either {} as a argument placeholder -and will fill it with Argument 1, the first argument. -You can also use {0} to have the first argument somewhere else. -Or {3} to skip to the last argument and finish with {} {} {} -If you only needed to edit this code part and not the snippet, -you can use instead `snp unique_example -e` (not -E). -Please consult the --help for the full list of commands ! -"; +and will fill it with every subsequent argument provided. +You can also write {0}, {3}, etc. to use a specific argument +instead of using them in order. +To edit only this text and not the whole code, you can use +`snp unique_example -e` and to edit all parameters +(name, default arguments and content) use -E or --edit-all. +Please consult the --help for the full list of commands !"; let snp = Snippet::new( "unique_example".to_string(), arguments.iter().map(|s| s.to_string()).collect(), From ba6dd6f70ade7bf21bc3fda4143f4e86daed70c8 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 25 May 2023 20:26:16 +0200 Subject: [PATCH 8/8] v1.0.6 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index fa14dad..47f94e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "snp" authors = ["Dandaedre"] -version = "1.0.5" +version = "1.0.6" edition = "2021" [features]