diff --git a/.gitignore b/.gitignore index 3ca43ae..193d30e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + + +# Added by cargo + +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..38d1ed7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "snp" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.2.7", features = ["derive"] } +serde = { version = "1.0.163", features = ["derive"] } diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..39c482c --- /dev/null +++ b/TODO.md @@ -0,0 +1,8 @@ +## Features +### --new (name) +- Create a new snippet with given name at the default location (where tho ?) + +### name args +- Use the snippet name with one or more args +- Args must be split up +- diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..619c994 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,58 @@ +use clap::Parser; +use serde::{Deserialize, Serialize}; + +#[derive(Parser, Debug)] +#[command(author, version, about)] +struct Cli { + #[arg()] + snipplet: String, + + #[arg(long, default_value_t = false)] + create: bool, + + #[arg(help = "List of args to give to the snipplet")] + args: Vec, +} + +fn main() { + let cli = Cli::parse(); + match cli.create { + true => create_snippet(), + false => print_snipped(), + } + println!("{:?}", cli); +} + +/// A snippet ready to be Serialized/Deserialized +#[derive(Deserialize, Serialize)] +pub struct Snippet { + /// Akin to path, the name of the snippet is where to store it + name: String, + + /// The default value of all args + args: Vec, + + /// The base string to format + string: String, +} + +impl Snippet { + /// Create a new snippet + pub fn new(name: String, args: Vec, string: String) -> Self { + Snippet { name, args, string } + } + + /// Save the snippet at the default location under it's name + pub fn save(&self) -> Result<(), ()> { + Ok(()) + } + + /// Write to stdout the snipped with either default arguments or given arguments + pub fn print(&self) -> Result<(), ()> { + Ok(()) + } +} + +// pub struct AccessError{ + +// }