Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Catto | d341128997 | |
Catto | 46a4c7c541 | |
Catto | 7b4228907d |
|
@ -0,0 +1,35 @@
|
||||||
|
A silly little CLI note app
|
||||||
|
|
||||||
|
[Downloads under Releases](https://git.maidsin.space/catto/snotes/releases)
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: snotes [OPTIONS]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c, --create <CREATE> Create a new note: --create "Hello World" [default: ]
|
||||||
|
-s, --show Show the latest entries
|
||||||
|
--showall Show all entries
|
||||||
|
-t, --tag <TAG> Append or show entries with tag [default: ]
|
||||||
|
-d, --delete Delete the latest entry
|
||||||
|
-h, --help Print help
|
||||||
|
-V, --version Print version
|
||||||
|
```
|
||||||
|
|
||||||
|
# Demo
|
||||||
|
|
||||||
|
![demo gif](media/demo.gif)
|
||||||
|
|
||||||
|
# Building (Linux)
|
||||||
|
|
||||||
|
- Clone this repo `git clone "https://git.maidsin.space/catto/snotes.git"`
|
||||||
|
- [Install Rust](https://www.rust-lang.org/learn/get-started)
|
||||||
|
- run `carog build --release` in the root of the project
|
||||||
|
- You now have a working `snotes` binary file under `target/release`
|
||||||
|
|
||||||
|
Windows Builds might be a bit more involved since this dependency builds and bundles sqlite3 [https://github.com/rusqlite/rusqlite](https://github.com/rusqlite/rusqlite)
|
||||||
|
|
||||||
|
# Installation
|
||||||
|
|
||||||
|
You could copy the `snotes` binary into a `/usr/bin` or `~/.local/bin` folder, one that's part of your system PATH so you can run it anywhere.
|
Binary file not shown.
After Width: | Height: | Size: 252 KiB |
48
src/main.rs
48
src/main.rs
|
@ -18,6 +18,9 @@ struct Args {
|
||||||
/// Append or show entries with tag
|
/// Append or show entries with tag
|
||||||
#[arg(short, long, default_value_t = String::new())]
|
#[arg(short, long, default_value_t = String::new())]
|
||||||
tag: String,
|
tag: String,
|
||||||
|
/// Delete the latest entry
|
||||||
|
#[arg(short, long, default_value_t = false)]
|
||||||
|
delete: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Note {
|
struct Note {
|
||||||
|
@ -30,36 +33,53 @@ fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
match init_db() {
|
match init_db() {
|
||||||
Ok(_) => println!(),
|
Ok(_) => (),
|
||||||
Err(e) => println!("Failed to initialize DB: {}", e),
|
Err(e) => println!("Failed to initialize DB: {}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
if args.show {
|
if args.show {
|
||||||
match show_notes(false, &args.tag) {
|
match show_notes(false, &args.tag) {
|
||||||
Ok(_) => println!(),
|
Ok(_) => (),
|
||||||
Err(e) => println!("Failed to show DB: {}", e),
|
Err(e) => println!("Failed to show DB: {}", e),
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.create != String::new() {
|
if args.create != String::new() {
|
||||||
match create_note(&args.create, &args.tag) {
|
match create_note(&args.create, &args.tag) {
|
||||||
Ok(_) => println!(),
|
Ok(_) => (),
|
||||||
Err(e) => println!("Failed to throw into DB: {}", e),
|
Err(e) => println!("Failed to throw into DB: {}", e),
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.showall {
|
if args.showall {
|
||||||
match show_notes(true, &args.tag) {
|
match show_notes(true, &args.tag) {
|
||||||
Ok(_) => println!(),
|
Ok(_) => (),
|
||||||
Err(e) => println!("Failed to show DB: {}", e),
|
Err(e) => println!("Failed to show DB: {}", e),
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.tag != String::new() && args.create == String::new() {
|
if args.tag != String::new() && args.create == String::new() {
|
||||||
match show_notes(true, &args.tag) {
|
match show_notes(true, &args.tag) {
|
||||||
Ok(_) => println!(),
|
Ok(_) => (),
|
||||||
Err(e) => println!("Failed to show DB: {}", e),
|
Err(e) => println!("Failed to show DB: {}", e),
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if args.delete {
|
||||||
|
match delete_latest_note() {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(e) => println!("Failed to delete: {}", e),
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
match show_notes(false, &args.tag) {
|
||||||
|
Ok(_) => println!(),
|
||||||
|
Err(e) => println!("Failed to show DB: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +97,7 @@ fn init_db() -> Result<()> {
|
||||||
";
|
";
|
||||||
|
|
||||||
match connection.execute(query_table, []) {
|
match connection.execute(query_table, []) {
|
||||||
Ok(v) => println!("INIT OK {}", v),
|
Ok(_) => (),
|
||||||
Err(e) => println!("INIT ERR {}", e),
|
Err(e) => println!("INIT ERR {}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,7 +109,7 @@ fn create_note(content: &String, tag: &String) -> Result<()> {
|
||||||
let connection = Connection::open(home)?;
|
let connection = Connection::open(home)?;
|
||||||
let date = Local::now();
|
let date = Local::now();
|
||||||
let date_string = date.format("%m-%d-%y %H:%M").to_string();
|
let date_string = date.format("%m-%d-%y %H:%M").to_string();
|
||||||
let tag_string = if tag.to_string() == String::new() {
|
let tag_string = if *tag == String::new() {
|
||||||
String::from("quick")
|
String::from("quick")
|
||||||
} else {
|
} else {
|
||||||
tag.to_string()
|
tag.to_string()
|
||||||
|
@ -138,3 +158,17 @@ fn show_notes(all: bool, tag: &String) -> Result<()> {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn delete_latest_note() -> Result<()> {
|
||||||
|
let home = home_dir().unwrap().join(".snotes.db");
|
||||||
|
let connection = Connection::open(home)?;
|
||||||
|
|
||||||
|
let query = String::from("DELETE FROM NOTES WHERE nid = (SELECT MAX(nid) FROM notes)");
|
||||||
|
|
||||||
|
match connection.execute(&query, []) {
|
||||||
|
Ok(v) => println!("DELETE OK {}", v),
|
||||||
|
Err(e) => println!("DELETE ERR {}", e),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue