tangled
alpha
login
or
join now
ngp.computer
/
tsk
A file-based task manager
0
fork
atom
overview
issues
pulls
pipelines
Allow find args in other commands
ngp.computer
1 year ago
515e9c01
21c81d34
+44
-27
2 changed files
expand all
collapse all
unified
split
src
main.rs
workspace.rs
+37
-25
src/main.rs
···
79
80
/// Use fuzzy finding with `fzf` to search for a task
81
Find {
82
-
/// Include the contents of tasks in the search criteria.
83
-
#[arg(short = 'b', default_value_t = false)]
84
-
search_body: bool,
85
-
/// Include archived tasks in the search criteria. Combine with `-b` to include archived
86
-
/// bodies in the search criteria.
87
-
#[arg(short = 'a', default_value_t = false)]
88
-
search_archived: bool,
89
-
90
-
#[arg(short = 't', default_value_t = true)]
91
full_id: bool,
92
},
93
···
137
#[arg(short = 'r', value_name = "RELATIVE", default_value_t = 0)]
138
relative_id: u32,
139
140
-
/// Use fuzzy finding to search for and select a task.
141
-
/// Does not support searching task bodies or archived tasks.
0
0
0
0
0
0
0
142
#[arg(short = 'f', value_name = "FIND", default_value_t = false)]
143
find: bool,
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
144
}
145
146
impl From<TaskId> for TaskIdentifier {
···
148
if let Some(id) = value.id.map(Id::from).or(value.tsk_id) {
149
TaskIdentifier::Id(id)
150
} else {
151
-
if value.find {
152
-
TaskIdentifier::Find
0
0
0
153
} else {
154
TaskIdentifier::Relative(value.relative_id)
155
}
···
168
Commands::Edit { task_id } => command_edit(dir, task_id),
169
Commands::Completion { shell } => command_completion(shell),
170
Commands::Drop => command_drop(dir),
171
-
Commands::Find {
172
-
full_id,
173
-
search_body,
174
-
search_archived,
175
-
} => command_find(dir, full_id, search_body, search_archived),
176
Commands::Rot => Workspace::from_path(dir).unwrap().rot(),
177
Commands::Tor => Workspace::from_path(dir).unwrap().tor(),
178
Commands::Reprioritize { task_id } => command_reprioritize(dir, task_id),
···
277
Ok(())
278
}
279
280
-
fn command_find(
281
-
dir: PathBuf,
282
-
full_id: bool,
283
-
search_body: bool,
284
-
search_archived: bool,
285
-
) -> Result<()> {
286
-
let id = Workspace::from_path(dir)?.search(None, search_body, search_archived)?;
287
if let Some(id) = id {
288
if full_id {
289
println!("{id}");
···
79
80
/// Use fuzzy finding with `fzf` to search for a task
81
Find {
82
+
#[command(flatten)]
83
+
args: FindArgs,
84
+
/// Whether to print the full TSK-ID (instead of just an integer)
85
+
#[arg(short = 'F', default_value_t = true)]
0
0
0
0
0
86
full_id: bool,
87
},
88
···
132
#[arg(short = 'r', value_name = "RELATIVE", default_value_t = 0)]
133
relative_id: u32,
134
135
+
#[command(flatten)]
136
+
find: Find,
137
+
}
138
+
139
+
/// Use fuzzy finding to search for and select a task.
140
+
/// Does not support searching task bodies or archived tasks.
141
+
#[derive(Args)]
142
+
#[group(required = false, multiple = true)]
143
+
struct Find {
144
#[arg(short = 'f', value_name = "FIND", default_value_t = false)]
145
find: bool,
146
+
#[command(flatten)]
147
+
args: FindArgs,
148
+
}
149
+
150
+
#[derive(Args)]
151
+
#[group(required = false, multiple = false)]
152
+
struct FindArgs {
153
+
/// Include the contents of tasks in the search criteria.
154
+
#[arg(short = 'b', default_value_t = false)]
155
+
search_body: bool,
156
+
/* TODO: implement this
157
+
/// Include archived tasks in the search criteria. Combine with `-b` to include archived
158
+
/// bodies in the search criteria.
159
+
#[arg(short = 'a', default_value_t = false)]
160
+
search_archived: bool,
161
+
*/
162
}
163
164
impl From<TaskId> for TaskIdentifier {
···
166
if let Some(id) = value.id.map(Id::from).or(value.tsk_id) {
167
TaskIdentifier::Id(id)
168
} else {
169
+
if value.find.find {
170
+
TaskIdentifier::Find {
171
+
search_body: value.find.args.search_body,
172
+
archived: false,
173
+
}
174
} else {
175
TaskIdentifier::Relative(value.relative_id)
176
}
···
189
Commands::Edit { task_id } => command_edit(dir, task_id),
190
Commands::Completion { shell } => command_completion(shell),
191
Commands::Drop => command_drop(dir),
192
+
Commands::Find { args, full_id } => command_find(dir, full_id, args),
0
0
0
0
193
Commands::Rot => Workspace::from_path(dir).unwrap().rot(),
194
Commands::Tor => Workspace::from_path(dir).unwrap().tor(),
195
Commands::Reprioritize { task_id } => command_reprioritize(dir, task_id),
···
294
Ok(())
295
}
296
297
+
fn command_find(dir: PathBuf, full_id: bool, find_args: FindArgs) -> Result<()> {
298
+
let id = Workspace::from_path(dir)?.search(None, find_args.search_body, false)?;
0
0
0
0
0
299
if let Some(id) = id {
300
if full_id {
301
println!("{id}");
+7
-2
src/workspace.rs
···
50
pub enum TaskIdentifier {
51
Id(Id),
52
Relative(u32),
53
-
Find,
54
}
55
56
impl From<Id> for TaskIdentifier {
···
99
let stack_item = stack.get(r as usize).ok_or(Error::NoTasks)?;
100
Ok(stack_item.id)
101
}
102
-
TaskIdentifier::Find => self.search(None, false, false)?.ok_or(Error::NotSelected),
0
0
0
0
0
103
}
104
}
105
···
50
pub enum TaskIdentifier {
51
Id(Id),
52
Relative(u32),
53
+
Find { search_body: bool, archived: bool },
54
}
55
56
impl From<Id> for TaskIdentifier {
···
99
let stack_item = stack.get(r as usize).ok_or(Error::NoTasks)?;
100
Ok(stack_item.id)
101
}
102
+
TaskIdentifier::Find {
103
+
search_body,
104
+
archived,
105
+
} => self
106
+
.search(None, search_body, archived)?
107
+
.ok_or(Error::NotSelected),
108
}
109
}
110