krabby_cli/
commands.rs

1use clap::{Args, Subcommand};
2
3#[derive(Debug, Subcommand)]
4pub enum Commands {
5    /// Goes to project path
6    Cd { project_name: String },
7    /// Manage project hook
8    Hook(Hook),
9    /// Executes given string
10    #[clap(visible_alias = "r")]
11    Run { script: String },
12    /// Manage projects on database
13    Project(Project),
14    /// Manage scripts of a project
15    Script(Script),
16    /// Print the helper script
17    Shell(Shell),
18}
19
20#[derive(Debug, Args)]
21#[command(args_conflicts_with_subcommands = true)]
22pub struct Hook {
23    #[command(subcommand)]
24    pub command: Option<HookCommands>,
25}
26
27#[derive(Debug, Subcommand)]
28pub enum HookCommands {
29    /// Define hook to execute whenever you enter the project
30    Set {
31        #[clap(value_delimiter = ',')]
32        hook: Vec<String>,
33    },
34}
35
36#[derive(Debug, Args)]
37#[command(args_conflicts_with_subcommands = true)]
38pub struct Shell {
39    #[command(subcommand)]
40    pub command: Option<ShellCommands>,
41}
42
43#[derive(Debug, Subcommand)]
44pub enum ShellCommands {
45    /// Print `kb` function
46    #[clap(visible_alias = "sh")]
47    Bash,
48    Zsh,
49}
50
51#[derive(Debug, Args)]
52#[command(args_conflicts_with_subcommands = true)]
53pub struct Script {
54    #[command(subcommand)]
55    pub command: Option<ScriptCommands>,
56}
57
58#[derive(Debug, Subcommand)]
59pub enum ScriptCommands {
60    /// Add script to Krabby project file
61    Add {
62        /// Script name to be registered
63        script_name: String,
64        /// Script command to be executed
65        script_command: String,
66    },
67    /// Remove script to Krabby project file
68    #[clap(visible_alias = "rm")]
69    Remove { script: String },
70    /// List available scripts
71    #[clap(visible_alias = "ls")]
72    List,
73}
74
75#[derive(Debug, Args)]
76#[command(args_conflicts_with_subcommands = true)]
77pub struct Project {
78    #[command(subcommand)]
79    pub command: ProjectCommands,
80}
81
82#[derive(Debug, Subcommand)]
83pub enum ProjectCommands {
84    /// Add project to Krabby database
85    Add {
86        /// Project name to be registered
87        project_name: String,
88        /// Project path
89        project_path: String,
90    },
91    /// Go to project directory
92    #[clap(visible_alias = "go")]
93    Cd { project_name: String },
94    /// List all registered projects
95    #[clap(visible_alias = "ls")]
96    List,
97    /// Remove project from Krabby database
98    #[clap(visible_alias = "rm")]
99    Remove { project_name: String },
100    /// Initialize a krabby project file
101    Init {
102        /// Specify the name of the project (defaults to directory name)
103        project_name: Option<String>,
104    },
105}