1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use clap::Parser;

use crate::remote::ListRemoteCliArgs;

use super::common::ListArgs;

#[derive(Parser)]
pub struct ReleaseCommand {
    #[clap(subcommand)]
    pub subcommand: ReleaseSubcommand,
}

#[derive(Parser)]
pub enum ReleaseSubcommand {
    #[clap(about = "List releases")]
    List(ListArgs),
}

impl From<ReleaseCommand> for ReleaseOptions {
    fn from(options: ReleaseCommand) -> Self {
        match options.subcommand {
            ReleaseSubcommand::List(options) => options.into(),
        }
    }
}

impl From<ListArgs> for ReleaseOptions {
    fn from(args: ListArgs) -> Self {
        ReleaseOptions::List(args.into())
    }
}

pub enum ReleaseOptions {
    List(ListRemoteCliArgs),
}

#[cfg(test)]
mod test {
    use crate::cli::{Args, Command};

    use super::*;

    #[test]
    fn test_release_cli_list() {
        let args = Args::parse_from(vec![
            "gr",
            "rl",
            "list",
            "--from-page",
            "1",
            "--to-page",
            "2",
        ]);
        let list_args = match args.command {
            Command::Release(ReleaseCommand {
                subcommand: ReleaseSubcommand::List(options),
            }) => {
                assert_eq!(options.from_page, Some(1));
                assert_eq!(options.to_page, Some(2));
                options
            }
            _ => panic!("Expected ReleaseCommand"),
        };
        let options: ReleaseOptions = list_args.into();
        match options {
            ReleaseOptions::List(args) => {
                assert_eq!(args.from_page, Some(1));
                assert_eq!(args.to_page, Some(2));
            }
        }
    }
}