Initial WIP
This commit is contained in:
parent
e64c763a9b
commit
c1f739598a
|
|
@ -14,3 +14,8 @@ Cargo.lock
|
|||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
|
|
|||
|
|
@ -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"] }
|
||||
|
|
@ -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
|
||||
-
|
||||
|
|
@ -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<String>,
|
||||
}
|
||||
|
||||
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<String>,
|
||||
|
||||
/// The base string to format
|
||||
string: String,
|
||||
}
|
||||
|
||||
impl Snippet {
|
||||
/// Create a new snippet
|
||||
pub fn new(name: String, args: Vec<String>, 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{
|
||||
|
||||
// }
|
||||
Reference in New Issue