about summary refs log tree commit diff stats
path: root/pkgs/by-name/ts/tskm/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/by-name/ts/tskm/src/cli.rs')
-rw-r--r--pkgs/by-name/ts/tskm/src/cli.rs96
1 files changed, 76 insertions, 20 deletions
diff --git a/pkgs/by-name/ts/tskm/src/cli.rs b/pkgs/by-name/ts/tskm/src/cli.rs
index f38d7879..23d9545f 100644
--- a/pkgs/by-name/ts/tskm/src/cli.rs
+++ b/pkgs/by-name/ts/tskm/src/cli.rs
@@ -11,12 +11,15 @@
 use std::{ffi::OsStr, path::PathBuf};
 
 use anyhow::{bail, Result};
-use clap::{builder::StyledStr, ArgAction, Parser, Subcommand};
+use clap::{builder::StyledStr, ArgAction, Parser, Subcommand, ValueEnum};
 use clap_complete::{ArgValueCompleter, CompletionCandidate};
 use url::Url;
 
 use crate::{
-    interface::{input::Input, project::ProjectName},
+    interface::{
+        input::{Input, Tag},
+        project::ProjectName,
+    },
     state, task,
 };
 
@@ -25,7 +28,7 @@ use crate::{
 /// This is the core interface to the system-integrated task management
 ///
 /// `tskm` effectively combines multiple applications together:
-/// - `taskwarrior` projects are raised connected to `firefox` profiles, making it possible to “open”
+/// - `taskwarrior` projects are connected to `qutebrowser` profiles, making it possible to “open”
 ///   a project.
 ///
 /// - Every `taskwarrior` project has a determined `neorg` path, so that extra information for a
@@ -66,7 +69,7 @@ pub enum Command {
         command: NeorgCommand,
     },
 
-    /// Interface with the Firefox profile of each project.
+    /// Interface with the Qutebrowser profile of each project.
     Open {
         #[command(subcommand)]
         command: OpenCommand,
@@ -91,8 +94,8 @@ pub enum NeorgCommand {
     /// Open the `neorg` project associated with id of the task.
     Task {
         /// The working set id of the task
-        #[arg(value_parser = task_from_working_set_id, add = ArgValueCompleter::new(complete_task_id))]
-        id: task::Task,
+        #[arg(value_name = "ID", value_parser = task_from_working_set_id, add = ArgValueCompleter::new(complete_task_id))]
+        task: task::Task,
     },
 }
 
@@ -108,38 +111,55 @@ fn task_from_working_set_id(id: &str) -> Result<task::Task> {
 
 #[derive(Subcommand, Debug)]
 pub enum OpenCommand {
-    /// Open each project's Firefox profile consecutively, that was opened since the last review.
+    /// Open each project's Qutebrowser profile consecutively, that was opened since the last review.
     ///
     /// This allows you to remove stale opened tabs and to commit open tabs to the `inputs`.
-    Review,
+    Review {
+        /// Review all projects, if they contain tabs
+        #[arg(short, long, default_value_t)]
+        non_empty: bool,
+    },
 
-    /// Opens Firefox with either the supplied project or the currently active project profile.
+    /// Opens Qutebrowser with either the supplied project or the currently active project profile.
     Project {
         /// The project to open.
         #[arg(value_parser = task::Project::from_project_string, add = ArgValueCompleter::new(complete_project))]
         project: task::Project,
 
-        /// The URL to open.
-        url: Option<Url>,
+        /// The URLs to open.
+        urls: Option<Vec<Url>>,
     },
 
-    /// Open a selected project in it's Firefox profile.
+    /// Open a selected project in it's Qutebrowser profile.
     ///
     /// This will use rofi's dmenu mode to select one project from the list of all registered
     /// projects.
     Select {
-        /// The URL to open.
-        url: Option<Url>,
+        /// The URLs to open.
+        urls: Option<Vec<Url>>,
     },
 
     /// List all open tabs in the project.
     ListTabs {
-        /// The project to open.
+        /// The projects to open.
         #[arg(value_parser = task::Project::from_project_string, add = ArgValueCompleter::new(complete_project))]
-        project: Option<task::Project>,
+        projects: Option<Vec<task::Project>>,
+
+        /// Only show the tabs, that are in this mode
+        #[arg(short, long, conflicts_with = "projects")]
+        mode: Option<ListMode>,
     },
 }
 
+#[derive(Clone, Copy, ValueEnum, Debug)]
+pub enum ListMode {
+    // The tab contains no tabs.
+    Empty,
+
+    // The tab contains tabs.
+    NonEmpty,
+}
+
 #[derive(Subcommand, Debug)]
 pub enum InputCommand {
     /// Add URLs as inputs to be categorized.
@@ -153,7 +173,14 @@ pub enum InputCommand {
     /// Add all URLs in the file as inputs to be categorized.
     ///
     /// This expects each line to contain one URL.
-    File { file: PathBuf },
+    File {
+        /// The file to read from.
+        file: PathBuf,
+
+        /// Additional tags to apply to every read URL in the file.
+        #[arg(add = ArgValueCompleter::new(complete_tag))]
+        tags: Vec<Tag>,
+    },
 
     /// Like 'review', but for the inputs that have previously been added.
     /// It takes a project in which to open the URLs.
@@ -164,7 +191,14 @@ pub enum InputCommand {
     },
 
     /// List all the previously added inputs.
-    List,
+    List {
+        /// Only list the inputs that have all the specified tags
+        #[arg(add = ArgValueCompleter::new(complete_tag))]
+        tags: Vec<Tag>,
+    },
+
+    /// Show all the available tags.
+    Tags {},
 }
 
 fn complete_task_id(current: &OsStr) -> Vec<CompletionCandidate> {
@@ -219,8 +253,6 @@ fn complete_task_id(current: &OsStr) -> Vec<CompletionCandidate> {
                 if project == current_project {
                     if let Some(out) = format_task(task, current, &mut state) {
                         output.push(out);
-                    } else {
-                        continue;
                     }
                 }
             }
@@ -274,3 +306,27 @@ fn complete_input_url(current: &OsStr) -> Vec<CompletionCandidate> {
 
     output
 }
+fn complete_tag(current: &OsStr) -> Vec<CompletionCandidate> {
+    let mut output = vec![];
+
+    let Some(current) = current.to_str() else {
+        return output;
+    };
+
+    if !current.starts_with('+') {
+        output.push(CompletionCandidate::new(format!("+{current}")));
+    }
+
+    output
+}
+
+#[cfg(test)]
+mod test {
+    use clap::CommandFactory;
+
+    use super::CliArgs;
+    #[test]
+    fn verify_cli() {
+        CliArgs::command().debug_assert();
+    }
+}