cargo_run/commands/
mod.rs

1//! This module defines the commands and their execution logic for the cargo-script CLI tool.
2//!
3//! It includes functionalities to run scripts, initialize the Scripts.toml file, and handle script execution.
4
5use clap::{Subcommand, ArgAction, ValueEnum};
6
7/// Enum representing the different commands supported by the CLI tool.
8#[derive(Subcommand, Debug, Clone)]
9pub enum Commands {
10    #[command(about = "Run a script by name defined in Scripts.toml", visible_alias = "r")]
11    Run {
12        #[arg(value_name = "SCRIPT_NAME")]
13        script: Option<String>,
14        #[arg(short, long, value_name = "KEY=VALUE", action = ArgAction::Append)]
15        env: Vec<String>,
16        /// Preview what would be executed without actually running it
17        #[arg(long)]
18        dry_run: bool,
19        /// Suppress all output except errors
20        #[arg(short, long)]
21        quiet: bool,
22        /// Show detailed output
23        #[arg(short = 'v', long)]
24        verbose: bool,
25        /// Don't show performance metrics after execution
26        #[arg(long)]
27        no_metrics: bool,
28        /// Interactive script selection
29        #[arg(short, long)]
30        interactive: bool,
31    },
32    #[command(about = "Initialize a Scripts.toml file in the current directory")]
33    Init,
34    #[command(about = "Show all script names and descriptions defined in Scripts.toml")]
35    Show {
36        /// Suppress all output except errors
37        #[arg(short, long)]
38        quiet: bool,
39        /// Show detailed output
40        #[arg(short = 'v', long)]
41        verbose: bool,
42        /// Filter scripts by name or description
43        #[arg(short, long, value_name = "PATTERN")]
44        filter: Option<String>,
45    },
46    #[command(about = "Generate shell completion scripts")]
47    Completions {
48        /// Shell to generate completions for
49        #[arg(value_enum)]
50        shell: Shell,
51    },
52    #[command(about = "Validate Scripts.toml syntax, script references, and tool requirements")]
53    Validate {
54        /// Suppress all output except errors
55        #[arg(short, long)]
56        quiet: bool,
57        /// Show detailed output
58        #[arg(short = 'v', long)]
59        verbose: bool,
60    },
61}
62
63/// Supported shells for completion generation
64#[derive(ValueEnum, Clone, Debug)]
65#[value(rename_all = "kebab-case")]
66pub enum Shell {
67    Bash,
68    Zsh,
69    Fish,
70    #[value(name = "power-shell")]
71    PowerShell,
72}
73
74pub mod init;
75pub mod script;
76pub mod show;
77pub mod completions;
78pub mod validate;