Skip to main content

things3_cloud/commands/
mod.rs

1pub mod anytime;
2pub mod area;
3pub mod areas;
4pub mod delete;
5pub mod edit;
6pub mod find;
7pub mod inbox;
8pub mod logbook;
9pub mod mark;
10pub mod new;
11pub mod project;
12pub mod projects;
13pub mod reorder;
14pub mod schedule;
15pub mod set_auth;
16pub mod someday;
17pub mod tags;
18pub mod today;
19pub mod upcoming;
20
21use crate::app::Cli;
22use crate::cmd_ctx::{CmdCtx, DefaultCmdCtx};
23use anyhow::Result;
24use clap::{Args, Subcommand};
25
26pub trait Command {
27    fn run_with_ctx(
28        &self,
29        cli: &Cli,
30        out: &mut dyn std::io::Write,
31        ctx: &mut dyn CmdCtx,
32    ) -> Result<()>;
33
34    fn run(&self, cli: &Cli, out: &mut dyn std::io::Write) -> Result<()> {
35        let mut ctx = DefaultCmdCtx::from_cli(cli);
36        self.run_with_ctx(cli, out, &mut ctx)
37    }
38}
39
40#[derive(Debug, Default, Clone, Args)]
41pub struct DetailedArgs {
42    /// Show notes beneath each task
43    #[arg(long)]
44    pub detailed: bool,
45}
46
47#[derive(Debug, Default, Clone, Args)]
48pub struct TagDeltaArgs {
49    #[arg(long = "add-tags", help = "Comma-separated tags to add (titles or UUID prefixes)")]
50    pub add_tags: Option<String>,
51    #[arg(long = "remove-tags", help = "Comma-separated tags to remove (titles or UUID prefixes)")]
52    pub remove_tags: Option<String>,
53}
54
55#[derive(Debug, Subcommand)]
56pub enum Commands {
57    #[command(about = "Show the Inbox")]
58    Inbox(inbox::InboxArgs),
59    #[command(about = "Show the Today view (default)")]
60    Today(today::TodayArgs),
61    #[command(about = "Show tasks scheduled for the future")]
62    Upcoming(upcoming::UpcomingArgs),
63    #[command(about = "Show the Anytime view")]
64    Anytime(anytime::AnytimeArgs),
65    #[command(about = "Show the Someday view")]
66    Someday(someday::SomedayArgs),
67    #[command(about = "Show the Logbook")]
68    Logbook(logbook::LogbookArgs),
69    #[command(about = "Show, create, or edit projects")]
70    Projects(projects::ProjectsArgs),
71    #[command(about = "Show all tasks in a project")]
72    Project(project::ProjectArgs),
73    #[command(about = "Show or create areas")]
74    Areas(areas::AreasArgs),
75    #[command(about = "Show projects and tasks in an area")]
76    Area(area::AreaArgs),
77    #[command(about = "Show or edit tags")]
78    Tags(tags::TagsArgs),
79    #[command(about = "Create a new task")]
80    New(new::NewArgs),
81    #[command(about = "Edit a task title, container, notes, tags, or checklist items")]
82    Edit(edit::EditArgs),
83    #[command(about = "Mark a task done, incomplete, or canceled")]
84    Mark(mark::MarkArgs),
85    #[command(about = "Set when and deadline")]
86    Schedule(schedule::ScheduleArgs),
87    #[command(about = "Reorder item relative to another item")]
88    Reorder(reorder::ReorderArgs),
89    #[command(about = "Delete tasks/projects/headings/areas")]
90    Delete(delete::DeleteArgs),
91    #[command(about = "Configure Things Cloud credentials")]
92    SetAuth(set_auth::SetAuthArgs),
93    #[command(about = "Search and filter tasks")]
94    Find(find::FindArgs),
95}
96
97impl Command for Commands {
98    fn run_with_ctx(
99        &self,
100        cli: &Cli,
101        out: &mut dyn std::io::Write,
102        ctx: &mut dyn CmdCtx,
103    ) -> Result<()> {
104        match self {
105            Commands::Inbox(args) => args.run_with_ctx(cli, out, ctx),
106            Commands::Today(args) => args.run_with_ctx(cli, out, ctx),
107            Commands::Upcoming(args) => args.run_with_ctx(cli, out, ctx),
108            Commands::Anytime(args) => args.run_with_ctx(cli, out, ctx),
109            Commands::Someday(args) => args.run_with_ctx(cli, out, ctx),
110            Commands::Logbook(args) => args.run_with_ctx(cli, out, ctx),
111            Commands::Projects(args) => args.run_with_ctx(cli, out, ctx),
112            Commands::Project(args) => args.run_with_ctx(cli, out, ctx),
113            Commands::Areas(args) => args.run_with_ctx(cli, out, ctx),
114            Commands::Area(args) => args.run_with_ctx(cli, out, ctx),
115            Commands::Tags(args) => args.run_with_ctx(cli, out, ctx),
116            Commands::New(args) => args.run_with_ctx(cli, out, ctx),
117            Commands::Edit(args) => args.run_with_ctx(cli, out, ctx),
118            Commands::Mark(args) => args.run_with_ctx(cli, out, ctx),
119            Commands::Schedule(args) => args.run_with_ctx(cli, out, ctx),
120            Commands::Reorder(args) => args.run_with_ctx(cli, out, ctx),
121            Commands::Delete(args) => args.run_with_ctx(cli, out, ctx),
122            Commands::SetAuth(args) => args.run_with_ctx(cli, out, ctx),
123            Commands::Find(args) => args.run_with_ctx(cli, out, ctx),
124        }
125    }
126}