phpup/
cli.rs

1use crate::commands::{self, Command};
2use crate::config::Config;
3
4#[derive(clap::Parser, Debug)]
5#[clap(
6    name = env!("CARGO_PKG_NAME"),
7    version = env!("CARGO_PKG_VERSION"),
8    bin_name = "phpup",
9    about = env!("CARGO_PKG_DESCRIPTION")
10)]
11pub struct Cli {
12    #[clap(flatten)]
13    pub config: Config,
14    #[clap(subcommand)]
15    pub subcmd: SubCommand,
16}
17
18#[derive(clap::Parser, Debug)]
19pub enum SubCommand {
20    /// Initialize and Print shell script required for PHP-UP
21    #[clap(bin_name = "init")]
22    Init(commands::Init),
23
24    /// List remote PHP versions
25    #[clap(bin_name = "list-remote", visible_aliases = &["ls-remote"])]
26    ListRemote(commands::ListRemote),
27
28    /// Install a new PHP version
29    #[clap(bin_name = "install")]
30    Install(commands::Install),
31
32    /// List local PHP versions
33    #[clap(bin_name = "list", visible_aliases = &["ls"])]
34    List(commands::ListLocal),
35
36    /// Switch PHP version
37    #[clap(bin_name = "use")]
38    Use(commands::Use),
39
40    /// Print the current PHP version
41    #[clap(bin_name = "current")]
42    Current(commands::Current),
43
44    /// Uninstall a PHP version
45    #[clap(bin_name = "uninstall")]
46    Uninstall(commands::Uninstall),
47
48    /// Alias a version to a common name
49    #[clap(bin_name = "alias")]
50    Alias(commands::Alias),
51
52    /// Remove an alias definition
53    #[clap(bin_name = "unalias")]
54    Unalias(commands::Unalias),
55
56    /// Set a version as the default version
57    #[clap(bin_name = "default")]
58    Default(commands::Default),
59
60    /// Print shell completions
61    #[clap(bin_name = "completions")]
62    Completions(commands::Completions),
63}
64
65impl SubCommand {
66    pub fn apply(&self, config: Config) {
67        use SubCommand::*;
68        match self {
69            Init(cmd) => cmd.apply(&config),
70            ListRemote(cmd) => cmd.apply(&config),
71            Install(cmd) => cmd.apply(&config),
72            List(cmd) => cmd.apply(&config),
73            Use(cmd) => cmd.apply(&config),
74            Current(cmd) => cmd.apply(&config),
75            Uninstall(cmd) => cmd.apply(&config),
76            Alias(cmd) => cmd.apply(&config),
77            Unalias(cmd) => cmd.apply(&config),
78            Default(cmd) => cmd.apply(&config),
79            Completions(cmd) => cmd.apply(&config),
80        };
81    }
82}