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
use clap::{Arg, Command};
pub mod data_file;
mod standup;
const DID: &str = "did";
const DOING: &str = "doing";
const BLOCKER: &str = "blocker";
const SIDEBAR: &str = "sidebar";
type LaydownResult<T> = Result<T, Box<dyn std::error::Error>>;
#[derive(Debug)]
pub struct Config {
did: Option<Vec<String>>,
doing: Option<Vec<String>>,
blocker: Option<Vec<String>>,
sidebar: Option<Vec<String>>,
clear: bool,
edit: Option<String>,
undo: bool,
archive: bool,
data_dir: bool,
}
pub fn get_args() -> LaydownResult<Config> {
let matches = Command::new("laydown")
.version("2.6.2")
.author("Bobby Dorrance")
.about("Keep track of your next Daily Stand Up")
.disable_help_subcommand(true)
.override_usage("laydown [COMMAND] \"<item>\" \"<item>\" \"<item>\"")
.subcommand(
Command::new(DID)
.about("Add items to the DID section of your standup")
.arg(Arg::new("items").num_args(1..)),
)
.subcommand(
Command::new(DOING)
.about("Add items to the DOING section of your standup")
.arg(Arg::new("items").num_args(1..)),
)
.subcommand(
Command::new(BLOCKER)
.about("Add items to the BLOCKER section of your standup")
.arg(Arg::new("items").num_args(1..)),
)
.subcommand(
Command::new(SIDEBAR)
.about("Add items to the SIDEBAR section of your standup")
.arg(Arg::new("items").num_args(1..)),
)
.arg(
Arg::new("clear")
.help("Remove all items from your Standup")
.long("clear")
.action(clap::ArgAction::SetTrue)
.display_order(5),
)
.arg(
Arg::new("edit")
.help("Directly access/edit data in your Standup")
.long("edit")
.value_name("EDITOR")
.num_args(0..=1)
.default_missing_value("vi")
.display_order(6),
)
.arg(
Arg::new("undo")
.help("Remove last item added to your Standup")
.long("undo")
.action(clap::ArgAction::SetTrue)
.display_order(7),
)
.arg(
Arg::new("archive")
.help("Archive today's Standup")
.long("archive")
.action(clap::ArgAction::SetTrue)
.display_order(8),
)
.arg(
Arg::new("data_dir")
.help("Print location of the laydown data directory")
.long("data-dir")
.action(clap::ArgAction::SetTrue)
.display_order(9),
)
.get_matches();
let did = match matches.subcommand() {
Some((DID, x)) => {
let items: Vec<String> = x
.get_many::<String>("items")
.unwrap_or_default()
.map(|x| x.to_string())
.collect();
Some(items)
}
_ => None,
};
let doing = match matches.subcommand() {
Some((DOING, x)) => {
let items: Vec<String> = x
.get_many::<String>("items")
.unwrap_or_default()
.map(|x| x.to_string())
.collect();
Some(items)
}
_ => None,
};
let blocker = match matches.subcommand() {
Some((BLOCKER, x)) => {
let items: Vec<String> = x
.get_many::<String>("items")
.unwrap_or_default()
.map(|x| x.to_string())
.collect();
Some(items)
}
_ => None,
};
let sidebar = match matches.subcommand() {
Some((SIDEBAR, x)) => {
let items: Vec<String> = x
.get_many::<String>("items")
.unwrap_or_default()
.map(|x| x.to_string())
.collect();
Some(items)
}
_ => None,
};
let clear: bool = matches.get_flag("clear");
let edit = matches
.get_one::<String>("edit")
.map(|editor| editor.to_owned());
let undo: bool = matches.get_flag("undo");
let archive: bool = matches.get_flag("archive");
let data_dir: bool = matches.get_flag("data_dir");
Ok(Config {
did,
doing,
blocker,
sidebar,
clear,
edit,
undo,
archive,
data_dir,
})
}
pub fn run(config: Config) -> LaydownResult<()> {
let file = data_file::get_path_to_laydown_data_file();
let mut show_standup_if_no_args_present = true;
if let Some(items) = config.did {
data_file::get_standup(&file).add_item(&file, DID, items);
show_standup_if_no_args_present = false;
}
if let Some(items) = config.doing {
data_file::get_standup(&file).add_item(&file, DOING, items);
show_standup_if_no_args_present = false;
}
if let Some(items) = config.blocker {
data_file::get_standup(&file).add_item(&file, BLOCKER, items);
show_standup_if_no_args_present = false;
}
if let Some(items) = config.sidebar {
data_file::get_standup(&file).add_item(&file, SIDEBAR, items);
show_standup_if_no_args_present = false;
}
if config.clear {
data_file::clear_data_from_file(&file);
show_standup_if_no_args_present = false;
}
if let Some(editor) = config.edit {
match std::env::var("EDITOR") {
Ok(user_default_editor) => data_file::manually_edit_file(&file, user_default_editor),
Err(_) => data_file::manually_edit_file(&file, editor),
}
show_standup_if_no_args_present = false;
}
if config.undo {
data_file::get_standup(&file).undo(&file);
show_standup_if_no_args_present = false;
}
if config.archive {
data_file::archive(&file);
show_standup_if_no_args_present = false;
}
if config.data_dir {
println!("{}", data_file::get_laydown_data_directory().display());
show_standup_if_no_args_present = false;
}
if show_standup_if_no_args_present {
let test = data_file::get_standup(&file);
print!("{}", test);
}
Ok(())
}