-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
228 lines (213 loc) · 7.99 KB
/
main.rs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#[macro_use]
extern crate prettytable;
#[macro_use]
extern crate lazy_static;
use crate::constants::*;
use anyhow::Result;
use clap::{App, Arg, SubCommand};
mod commands;
mod config;
mod constants;
mod jot;
mod utils;
// New commands `jot` to make a note `jot list` to cat notes
// maybe other shorthands? Anyways drop support for todos
// Make tags be more condensed and colorized.
fn main() -> Result<()> {
let config = config::load_config()?;
if config.journal_path.is_file() {
println!("journal incompatable with this version of jot! We now work on a directory instead of a single file");
return Ok(());
}
let matches = App::new("jot")
.version("0.2.0")
.about("Jot down quick notes")
.subcommand(
SubCommand::with_name("cat")
.about("Dump out the entire journal")
.arg(
Arg::with_name("RNG")
.short("d")
.long("date")
.value_name("RNG")
.takes_value(true)
.multiple(true)
.help("Filter by a human date range string"),
)
.arg(
Arg::with_name("TAG")
.short("t")
.long("tag")
.value_name("TAG")
.takes_value(true)
.multiple(true)
.help("Filter by a tag"),
)
.arg(
Arg::with_name("REVERSE")
.short("r")
.long("reverse")
.help("Reverse the output"),
)
.arg(
Arg::with_name("GREP")
.short("g")
.long("grep")
.value_name("GREP")
.takes_value(true)
.multiple(true)
.help("Filter by contents"),
),
)
// TODO: this command should be moved to the visualization sub commands like a -i flag
// or something.
.subcommand(
SubCommand::with_name("search")
.about("Perform interactive fuzzy searching on the journal."),
)
.subcommand(SubCommand::with_name("tags").about("List all tags"))
.subcommand(SubCommand::with_name(TODO).about("Write a todo"))
.subcommand(
SubCommand::with_name(TODOS)
.about("View all todos")
.arg(
Arg::with_name("TAG")
.short("t")
.long("tag")
.value_name("TAG")
.takes_value(true)
.multiple(true)
.help("Filter by a tag"),
)
.arg(
Arg::with_name("RANGE")
.short("d")
.long("date")
.value_name("RANGE")
.takes_value(true)
.multiple(false)
.help("Filter by a human date range string"),
)
.arg(
Arg::with_name("REVERSE")
.short("r")
.long("reverse")
.help("Reverse the output"),
)
.arg(
Arg::with_name("GREP")
.short("g")
.long("grep")
.value_name("GREP")
.takes_value(true)
.multiple(true)
.help("Filter by contents"),
),
)
.subcommand(SubCommand::with_name(NOTE).about("Write a note"))
.subcommand(
SubCommand::with_name(NOTES)
.about("View all notes")
.arg(
Arg::with_name("TAG")
.short("t")
.long("tag")
.value_name("TAG")
.takes_value(true)
.multiple(true)
.help("Filter by a tag"),
)
.arg(
Arg::with_name("RANGE")
.short("d")
.long("date")
.value_name("RANGE")
.takes_value(true)
.multiple(false)
.help("Filter by a human date range string"),
)
.arg(
Arg::with_name("REVERSE")
.short("r")
.long("reverse")
.help("Reverse the output"),
)
.arg(
Arg::with_name("GREP")
.short("g")
.long("grep")
.value_name("GREP")
.takes_value(true)
.multiple(true)
.help("Filter by contents"),
),
)
.subcommand(
SubCommand::with_name("edit")
.about("Edit the contents of a note/todo")
.arg(
Arg::with_name("ID")
.value_name("ID")
.takes_value(true)
.help("The id of the note you wish to edit"),
),
)
.subcommand(
SubCommand::with_name("complete")
.about("Complete a todo")
.arg(
Arg::with_name("ID")
.value_name("ID")
.takes_value(true)
.help("The id of the todo you wish to complete"),
),
)
.subcommand(
SubCommand::with_name("delete")
.about("Complete a todo")
.arg(
Arg::with_name("ID")
.value_name("ID")
.takes_value(true)
.help("The id of the todo you wish to delete"),
),
)
.get_matches();
if let Some(_matches) = matches.subcommand_matches(NOTE) {
let previous_uuids = commands::view::get_all_uuids(config.clone())
.unwrap_or(std::collections::HashSet::new());
return commands::create::create_note_command(config, &previous_uuids);
}
if let Some(_matches) = matches.subcommand_matches(TODO) {
let previous_uuids = commands::view::get_all_uuids(config.clone())
.unwrap_or(std::collections::HashSet::new());
return commands::create::create_todo_command(config, &previous_uuids);
}
if let Some(matches) = matches.subcommand_matches("edit") {
let id_or_uuid = matches.value_of("ID").unwrap();
return commands::edit::edit_jot_contents(config, id_or_uuid);
}
if let Some(matches) = matches.subcommand_matches("delete") {
let id_or_uuid = matches.value_of("ID").unwrap();
return commands::edit::delete_jot(config, id_or_uuid);
}
if let Some(matches) = matches.subcommand_matches("complete") {
let id_or_uuid = matches.value_of("ID").unwrap();
return commands::edit::mark_todo_complete_command(config, id_or_uuid);
}
if let Some(_matches) = matches.subcommand_matches("search") {
return commands::view::interactive_search(config);
}
// Commands for displaying various note types.
let read_sub_cmd = vec![NOTES, TODOS, "cat"]
.into_iter()
.find(|t| matches.subcommand_matches(t).is_some());
if let Some(read_cmd) = read_sub_cmd {
return commands::view::display(config, read_cmd, matches);
}
if let Some(_matches) = matches.subcommand_matches("tags") {
return commands::tags::tags_command(config);
}
// matches.print_help();
Ok(())
}