1use clap::Parser;
2
3#[derive(Parser)]
4pub struct AmpsCommand {
5 #[clap(subcommand)]
6 subcommand: Option<AmpsSubcommand>,
7}
8
9#[derive(Parser)]
10enum AmpsSubcommand {
11 #[clap(about = "List available amps")]
12 List,
13 #[clap(
14 name = "exec",
15 about = "Execute an amp, either by name or through prompt",
16 alias = "ex"
17 )]
18 Exec(ExecCommand),
19}
20
21#[derive(Parser)]
22struct ExecCommand {
23 #[clap()]
25 pub name: Option<String>,
26}
27
28pub enum AmpsOptions {
29 List,
30 Exec(String),
31}
32
33impl From<AmpsCommand> for AmpsOptions {
34 fn from(options: AmpsCommand) -> Self {
35 match options.subcommand {
36 Some(AmpsSubcommand::List) => AmpsOptions::List,
37 Some(AmpsSubcommand::Exec(options)) => options.into(),
38 None => AmpsOptions::List,
40 }
41 }
42}
43
44impl From<ExecCommand> for AmpsOptions {
45 fn from(options: ExecCommand) -> Self {
46 match options.name {
47 Some(name) => AmpsOptions::Exec(name),
48 None => AmpsOptions::Exec(String::new()),
50 }
51 }
52}
53
54#[cfg(test)]
55mod tests {
56 use crate::cli::{Args, Command};
57
58 use super::*;
59
60 #[test]
61 fn test_amps_list_command() {
62 let args = Args::parse_from(vec!["gr", "amps", "list"]);
63 match args.command {
64 Command::Amps(AmpsCommand {
65 subcommand: Some(AmpsSubcommand::List),
66 }) => {}
67 _ => panic!("Expected Amp ListCommand"),
68 }
69 }
70
71 #[test]
72 fn test_amps_exec_command() {
73 let args = Args::parse_from(vec!["gr", "amps", "exec", "amp-name"]);
74 match args.command {
75 Command::Amps(AmpsCommand {
76 subcommand: Some(AmpsSubcommand::Exec(ExecCommand { name })),
77 }) => {
78 assert_eq!(name, Some("amp-name".to_string()));
79 }
80 _ => panic!("Expected Amp ExecCommand"),
81 }
82 }
83}