command_vault/cli/
args.rs

1use clap::{Parser, Subcommand};
2
3#[derive(Parser, Debug)]
4#[command(author, version, about, long_about = None)]
5pub struct Cli {
6    #[command(subcommand)]
7    pub command: Commands,
8
9    /// Enable debug mode to see detailed command execution information
10    #[arg(short, long)]
11    pub debug: bool,
12}
13
14#[derive(Subcommand, Debug)]
15pub enum Commands {
16    /// Add a command to history
17    ///
18    /// Parameters can be specified using @name:description=default syntax
19    /// Examples:
20    ///   - Basic parameter: @filename
21    ///   - With description: @filename:Name of file to create
22    ///   - With default: @filename:Name of file to create=test.txt
23    Add {
24        /// Tags to add to the command
25        #[arg(short, long)]
26        tags: Vec<String>,
27        
28        /// Command to add
29        #[arg(trailing_var_arg = true, required = true)]
30        command: Vec<String>,
31    },
32    
33    /// Execute a command by id (in the current shell)
34    Exec {
35        /// Command ID to execute
36        command_id: i64,
37        
38        /// Enable debug mode
39        #[arg(long)]
40        debug: bool,
41    },
42    /// Search through command history
43    Search {
44        /// Search query
45        #[arg(required = true)]
46        query: String,
47        
48        /// Maximum number of results to show
49        #[arg(short, long, default_value = "10")]
50        limit: usize,
51    },
52    /// List all commands in chronological order
53    Ls {
54        /// Maximum number of results to show. Use 0 to show all commands.
55        #[arg(short, long, default_value = "50")]
56        limit: usize,
57        
58        /// Sort in ascending order (oldest first)
59        #[arg(short = 'a', long)]
60        asc: bool,
61    },
62    /// Tag related operations
63    Tag {
64        #[command(subcommand)]
65        action: TagCommands,
66    },
67    /// Initialize shell integration
68    ShellInit {
69        /// Shell to initialize (defaults to current shell)
70        #[arg(short, long)]
71        shell: Option<String>,
72    },
73    /// Delete a command from history
74    Delete {
75        /// Command ID to delete
76        #[arg(required = true)]
77        command_id: i64,
78    },
79}
80
81#[derive(Subcommand, Debug)]
82pub enum TagCommands {
83    /// Add tags to a command
84    Add {
85        /// Command ID to tag
86        #[arg(required = true)]
87        command_id: i64,
88        
89        /// Tags to add
90        #[arg(required = true)]
91        tags: Vec<String>,
92    },
93    /// Remove a tag from a command
94    Remove {
95        /// Command ID to remove tag from
96        #[arg(required = true)]
97        command_id: i64,
98        
99        /// Tag to remove
100        #[arg(required = true)]
101        tag: String,
102    },
103    /// List all tags and their usage count
104    List,
105    /// Search commands by tag
106    Search {
107        /// Tag to search for
108        #[arg(required = true)]
109        tag: String,
110        
111        /// Maximum number of results to show
112        #[arg(short, long, default_value = "10")]
113        limit: usize,
114    },
115}