pkg_rs/
cmd.rs

1use clap::{ColorChoice, Parser, Subcommand};
2
3#[cfg(feature = "cli_complation")]
4#[derive(Clone, Debug, clap::ValueEnum)]
5pub enum Shell {
6    Bash,
7    Fish,
8    Zsh,
9    Elvish,
10    Nushell,
11    #[allow(clippy::enum_variant_names)]
12    PowerShell, // NOTE: this is not needed really because this is unix only
13}
14
15#[derive(Parser)]
16#[command(name = "pkg")]
17#[command(version, about, long_about = None)] // Read from `Cargo.toml`
18#[command(color = ColorChoice::Always)] // Always show colors
19pub struct Cli {
20    #[command(subcommand)]
21    pub command: Commands,
22}
23
24#[derive(Subcommand)]
25pub enum Commands {
26    /// Sync packages with configuration (install/remove as configured)
27    #[command(alias = "sync", alias = "b", alias = "s")]
28    Build {
29        /// even update the installed packages via the update command
30        #[arg(short, long)]
31        update: bool,
32    },
33
34    /// Force sync all packages (reinstall everything)
35    Rebuild,
36
37    /// Update packages
38    #[command(alias = "u")]
39    Update {
40        /// Specific packages to update ( default: all )
41        packages: Option<Vec<String>>,
42    },
43
44    /// List installed packages
45    Info {
46        /// A packge to show information about ( default: all )
47        package: Option<Vec<String>>,
48    },
49
50    /// Link packages in PATH
51    Link,
52
53    /// Clean cache and temporary files
54    Clean,
55
56    /// Some notes can help insha'Allah
57    Docs,
58
59    #[cfg(feature = "cli_complation")]
60    /// Generate shell completion scripts for your clap::Command
61    #[command(alias = "compl")]
62    Completions {
63        /// Shell to generate completions for
64        shell: Shell,
65    },
66}
67
68// Helper function to parse CLI arguments
69pub fn parse_args() -> Cli {
70    Cli::parse()
71}