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