···1313use std::str::FromStr as _;
1414use std::{env::current_dir, io::Read};
1515use task::ParsedLink;
1616-use workspace::{Id, TaskIdentifier, Workspace};
1616+use workspace::{Id, Task, TaskIdentifier, Workspace};
17171818//use smol;
1919//use iocraft::prelude::*;
···4646 Init,
4747 /// Creates a new task, automatically assigning it a unique identifider and persisting
4848 Push {
4949+ /// Whether to open $EDITOR to edit the content of the task. The first line if the
5050+ /// resulting file will be the task's title. The body follows the title after two newlines,
5151+ /// similr to the format of a commit message.
5252+ #[arg(short = 'e', default_value_t = false)]
5353+ edit: bool,
5454+5555+ /// The body of the task. It may be specified as either a string using quotes or the
5656+ /// special character '-' to read from stdin.
5757+ #[arg(short = 'b')]
5858+ body: Option<String>,
5959+6060+ /// The title of the task as a raw string. It mus be proceeded by two dashes (--).
6161+ #[command(flatten)]
6262+ title: Title,
6363+ },
6464+ /// Creates a new task just like `push`, but instead of putting it at the top of the stack, it
6565+ /// puts it at the bottom
6666+ Append {
4967 /// Whether to open $EDITOR to edit the content of the task. The first line if the
5068 /// resulting file will be the task's title. The body follows the title after two newlines,
5169 /// similr to the format of a commit message.
···236254 let var_name = match cli.command {
237255 Commands::Init => command_init(dir),
238256 Commands::Push { edit, body, title } => command_push(dir, edit, body, title),
257257+ Commands::Append { edit, body, title } => command_append(dir, edit, body, title),
239258 Commands::List { all, count } => command_list(dir, all, count),
240259 Commands::Swap => command_swap(dir),
241260 Commands::Show {
···283302 Workspace::init(dir)
284303}
285304286286-fn command_push(dir: PathBuf, edit: bool, body: Option<String>, title: Title) -> Result<()> {
287287- let workspace = Workspace::from_path(dir)?;
305305+fn create_task(
306306+ workspace: &mut Workspace,
307307+ edit: bool,
308308+ body: Option<String>,
309309+ title: Title,
310310+) -> Result<Task> {
288311 let mut title = if let Some(title) = title.title {
289312 title
290313 } else if let Some(title) = title.title_simple {
···309332 }
310333 let task = workspace.new_task(title, body)?;
311334 workspace.handle_metadata(&task, None)?;
335335+ Ok(task)
336336+}
337337+338338+fn command_push(dir: PathBuf, edit: bool, body: Option<String>, title: Title) -> Result<()> {
339339+ let mut workspace = Workspace::from_path(dir)?;
340340+ let task = create_task(&mut workspace, edit, body, title)?;
312341 workspace.push_task(task)
342342+}
343343+344344+fn command_append(dir: PathBuf, edit: bool, body: Option<String>, title: Title) -> Result<()> {
345345+ let mut workspace = Workspace::from_path(dir)?;
346346+ let task = create_task(&mut workspace, edit, body, title)?;
347347+ workspace.append_task(task)
313348}
314349315350fn command_list(dir: PathBuf, all: bool, count: usize) -> Result<()> {