1use clap::Parser;
2
3use crate::cmds::user::UserCliArgs;
4
5use super::common::GetArgs;
6
7#[derive(Parser)]
8pub struct UserCommand {
9 #[clap(subcommand)]
10 subcommand: UserSubCommand,
11}
12
13#[derive(Parser)]
14enum UserSubCommand {
15 #[clap(about = "Gets user information")]
16 Get(GetUser),
17}
18
19#[derive(Parser)]
20struct GetUser {
21 #[clap()]
23 username: String,
24 #[clap(flatten)]
25 get_args: GetArgs,
26}
27
28impl From<UserCommand> for UserOptions {
29 fn from(cmd: UserCommand) -> Self {
30 match cmd.subcommand {
31 UserSubCommand::Get(options) => options.into(),
32 }
33 }
34}
35
36impl From<GetUser> for UserOptions {
37 fn from(options: GetUser) -> Self {
38 UserOptions::Get(
39 UserCliArgs::builder()
40 .username(options.username)
41 .get_args(options.get_args.into())
42 .build()
43 .unwrap(),
44 )
45 }
46}
47
48pub enum UserOptions {
49 Get(UserCliArgs),
50}
51
52#[cfg(test)]
53mod tests {
54 use crate::cli::{Args, Command};
55
56 use super::*;
57
58 #[test]
59 fn test_user_command() {
60 let args = Args::parse_from(["gr", "us", "get", "octocat"]);
61 let user_command = match args.command {
62 Command::User(cmd) => cmd,
63 _ => panic!("Expected user command"),
64 };
65 let options: UserOptions = user_command.into();
66 match options {
67 UserOptions::Get(args) => {
68 assert_eq!(args.username, "octocat");
69 }
70 }
71 }
72}