Skip to main content

things3_cloud/commands/
mod.rs

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