1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use clap::{Parser, ValueEnum};
#[derive(Debug, Parser)]
#[command(version, about, long_about = None)]
pub struct Args {
/// An optional name to operate on.
/// When storing notes, a randomly generated name is used by default.
/// When inspecting notes, the last created/referenced name is used by default.
#[arg(short, long)]
pub name: Option<String>,
/// The type of the note.
#[arg(short, long, default_value_t = NoteType::default())]
pub ty: NoteType,
/// Don't just print the value, but provide more information about it, like the origin and creation date.
#[arg(short, long)]
pub info: bool,
/// A short description describing the note. If the note type is a file, by default the description is set to it's path.
#[arg(short, long = "desc")]
pub description: Option<String>,
/// Overwrite the previous note, if it exists
#[arg(short, long)]
pub force: bool,
/// List all notes and exit
#[arg(short, long)]
pub list: bool,
}
#[derive(Copy, Clone, Debug, Default, ValueEnum)]
pub enum NoteType {
/// Raw text
#[default]
Raw,
/// A file
File,
}
impl std::fmt::Display for NoteType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
NoteType::Raw => "raw",
NoteType::File => "file",
}
)
}
}
pub fn get_piped_stdin() -> Option<String> {
if atty::is(atty::Stream::Stdin) {
None
} else {
Some(
std::io::stdin()
.lines()
.map(|v| v.unwrap())
.collect::<Vec<String>>()
.join("\n"),
)
}
}