87 lines
2.7 KiB
Rust
87 lines
2.7 KiB
Rust
//! A simple cli utility to manage snippet
|
|
|
|
#![warn(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#![allow(clippy::result_unit_err)]
|
|
|
|
use clap::Parser;
|
|
mod actions;
|
|
mod dynamic_formatter;
|
|
mod errors;
|
|
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 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, verbatim_doc_comment)]
|
|
pub struct Cli {
|
|
/// The Snippet name (and therefore his path)
|
|
#[arg(group = "mandatory", group = "mutex")]
|
|
snippet: Option<String>,
|
|
|
|
/// Try to create a Snippet with the given name and default arguments
|
|
#[arg(short, long, default_value_t = false, requires = "mandatory")]
|
|
create: bool,
|
|
|
|
/// Find the path of the snippet with the given name
|
|
#[arg(short, long, default_value_t = false, requires = "mandatory")]
|
|
path: bool,
|
|
|
|
/// Launch the editor and edit the Snippet content
|
|
#[arg(short, long, default_value_t = false, requires = "mandatory")]
|
|
edit: bool,
|
|
|
|
/// Launch the editor and edit the whole snippet
|
|
#[arg(
|
|
short = 'E',
|
|
long = "Edit",
|
|
default_value_t = false,
|
|
requires = "mandatory"
|
|
)]
|
|
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
|
|
#[arg(requires = "mandatory")]
|
|
args: Vec<String>,
|
|
|
|
/// Force the creation/moving/renaming of a Snippet even if it mean overwriting an existing one
|
|
#[arg(short, long, default_value_t = false, requires = "mandatory")]
|
|
force: bool,
|
|
|
|
/// Delete a snippet, takes precedence over everything
|
|
#[arg(short, long, default_value_t = false, requires = "mandatory")]
|
|
delete: bool,
|
|
|
|
/// Try to rename the Snippet (Use -f if the destination name already exist)
|
|
#[arg(short, long, requires = "mandatory")]
|
|
rename: Option<String>,
|
|
|
|
/// List all snippets in the snippet folder
|
|
#[arg(short, long, default_value_t = false, group = "mutex")]
|
|
list: bool,
|
|
}
|
|
|
|
/// Main entry point, everything is defered for testing and coverage
|
|
fn main() -> Result<(), errors::SnippetError> {
|
|
let cli = Cli::parse();
|
|
actions::execute_parsed_cli(cli)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use clap::CommandFactory;
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_cli_main() {
|
|
let cmd = Cli::command_for_update();
|
|
cmd.debug_assert();
|
|
}
|
|
}
|