diff options
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/cli.rs')
-rw-r--r-- | pkgs/by-name/ts/tskm/src/cli.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/pkgs/by-name/ts/tskm/src/cli.rs b/pkgs/by-name/ts/tskm/src/cli.rs index 99c8693e..bc79866a 100644 --- a/pkgs/by-name/ts/tskm/src/cli.rs +++ b/pkgs/by-name/ts/tskm/src/cli.rs @@ -1,9 +1,11 @@ use std::path::PathBuf; -use clap::{Parser, Subcommand}; +use anyhow::{bail, Result}; +use clap::{ArgAction, Parser, Subcommand}; use crate::{ interface::{input::Input, project::ProjectName}, + state::State, task, }; @@ -66,7 +68,21 @@ pub enum ProjectCommand { #[derive(Subcommand, Debug, Clone, Copy)] pub enum NeorgCommand { /// Open the `neorg` project associated with id of the task. - Task { id: task::Id }, + Task { + /// The working set id of the task + #[arg(value_parser = task_from_working_set_id)] + id: task::Task, + }, +} + +fn task_from_working_set_id(id: &str) -> Result<task::Task> { + let id: usize = id.parse()?; + let mut state = State::new_ro()?; + + let Some(task) = task::Task::from_working_set(id, &mut state)? else { + bail!("Working set id '{id}' is not valid!") + }; + Ok(task) } #[derive(Subcommand, Debug)] |