···11+use std::path::PathBuf;
22+use std::{env::current_dir, io::Read};
33+44+//use smol;
55+//use iocraft::prelude::*;
66+use clap::{Args, Parser, Subcommand};
77+use edit::edit as open_editor;
88+99+fn default_dir() -> PathBuf {
1010+ current_dir().unwrap()
1111+}
1212+1313+#[derive(Parser)]
1414+// TODO: add long_about
1515+#[command(version, about, long_about = None)]
1616+struct Cli {
1717+ #[arg(short = 'C', env = "TSK_DIR", value_name = "DIR")]
1818+ dir: Option<PathBuf>,
1919+ // TODO: other global options
2020+ #[command(subcommand)]
2121+ command: Commands,
2222+}
2323+2424+#[derive(Subcommand)]
2525+enum Commands {
2626+ /// Creates a new task, automatically assigning it a unique identifider and persisting
2727+ Push {
2828+ /// Whether to open $EDITOR to edit the content of the task. The first line if the
2929+ /// resulting file will be the task's title. The body follows the title after two newlines,
3030+ /// similr to the format of a commit message.
3131+ #[arg(short = 'e', default_value_t = false)]
3232+ edit: bool,
3333+3434+ /// The body of the task. It may be specified as either a string using quotes or the
3535+ /// special character '-' to read from stdin.
3636+ #[arg(short = 'b')]
3737+ body: Option<String>,
3838+3939+ /// The title of the task as a raw string. It mus be proceeded by two dashes (--).
4040+ #[command(flatten)]
4141+ title: Title,
4242+ },
4343+}
4444+4545+#[derive(Args)]
4646+#[group(required = true, multiple = false)]
4747+struct Title {
4848+ /// The title of the task. This is useful for when you also wish to specify the body of the
4949+ /// task as an argument (ie. with -b).
5050+ #[arg(short, value_name = "TITLE")]
5151+ title: Option<String>,
5252+5353+ #[arg(value_name = "TITLE")]
5454+ title_simple: Option<Vec<String>>,
5555+}
5656+5757+fn main() {
5858+ let cli = Cli::parse();
5959+ if let Commands::Push { edit, body, title } = cli.command {
6060+ let title = if let Some(title) = title.title {
6161+ eprintln!("TITLE: {}", title);
6262+ title
6363+ } else if let Some(title) = title.title_simple {
6464+ let joined = title.join(" ");
6565+ eprintln!("TITLE simple: {}", joined);
6666+ joined
6767+ } else {
6868+ "".to_string()
6969+ };
7070+ let mut body = body.unwrap_or_default();
7171+ if body == "-" {
7272+ // add newline so you can type directly in the shell
7373+ eprintln!("");
7474+ body.clear();
7575+ std::io::stdin()
7676+ .read_to_string(&mut body)
7777+ .expect("Failed to read stdin");
7878+ }
7979+ if edit {
8080+ body = open_editor(format!("{title}\n\n{body}")).expect("Failed to edit file");
8181+ }
8282+ eprintln!("BODY: {body}");
8383+ }
8484+}