1use crate::commands::{Commands, OutputFormat};
2use clap::{Parser, ValueHint};
3
4#[derive(Parser, Debug)]
17#[command(
18 name = "vkteams-bot-cli",
19 version = "0.6.0",
20 about = "VK Teams Bot CLI tool",
21 long_about = "A powerful command-line interface for interacting with VK Teams Bot API"
22)]
23pub struct Cli {
24 #[arg(short, long, value_name = "CONFIG", value_hint = ValueHint::FilePath)]
26 pub config: Option<String>,
27
28 #[arg(long, value_name = "PATH", value_hint = ValueHint::FilePath)]
30 pub save_config: Option<String>,
31
32 #[arg(short, long)]
34 pub verbose: bool,
35
36 #[arg(long, value_enum, default_value = "pretty")]
38 pub output: OutputFormat,
39
40 #[command(subcommand)]
41 pub command: Commands,
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47 use clap::{CommandFactory, Parser};
48
49 #[test]
50 fn test_cli_parsing_config_and_verbose() {
51 let args = [
52 "vkteams-bot-cli",
53 "--config",
54 "myconfig.toml",
55 "--save-config",
56 "out.toml",
57 "--verbose",
58 "config",
59 ];
60 let cli = Cli::parse_from(args);
61 assert_eq!(cli.config.as_deref(), Some("myconfig.toml"));
62 assert_eq!(cli.save_config.as_deref(), Some("out.toml"));
63 assert!(cli.verbose);
64 }
65
66 #[test]
67 fn test_cli_output_format_json() {
68 let args = ["vkteams-bot-cli", "--output", "json", "config"];
69 let cli = Cli::parse_from(args);
70 match cli.output {
71 OutputFormat::Json => (),
72 _ => panic!("Expected OutputFormat::Json"),
73 }
74 }
75
76 #[test]
77 fn test_cli_help_and_version() {
78 Cli::command().debug_assert();
79 let mut help_buf = Vec::new();
80 Cli::command().write_long_help(&mut help_buf).unwrap();
81 let help = String::from_utf8(help_buf).unwrap();
82 assert!(
83 help.contains(
84 "A powerful command-line interface for interacting with VK Teams Bot API"
85 )
86 );
87 let version = Cli::command().get_version().unwrap().to_string();
88 assert!(version.starts_with("0."));
89 }
90
91 #[test]
92 fn test_cli_invalid_output_format() {
93 let args = ["vkteams-bot-cli", "--output", "not_a_format", "config"];
94 let res = Cli::try_parse_from(args);
95 assert!(res.is_err());
96 }
97}