|
1 | | -use structopt::StructOpt; |
| 1 | +use clap::{Parser, ValueEnum}; |
| 2 | +use std::path::PathBuf; |
2 | 3 |
|
3 | 4 | #[allow(unused)] |
4 | | -#[derive(Debug, StructOpt, Clone)] |
5 | | -#[structopt(name = "emmylua-check", about = "EmmyLua Check")] |
| 5 | +#[derive(Debug, Parser, Clone)] |
6 | 6 | pub struct CmdArgs { |
7 | 7 | /// Configuration file paths. |
8 | 8 | /// If not provided, both ".emmyrc.json" and ".luarc.json" will be searched in the workspace |
9 | 9 | /// directory |
10 | | - #[structopt(short, long, use_delimiter = true, parse(from_os_str))] |
11 | | - pub config: Option<Vec<std::path::PathBuf>>, |
| 10 | + #[arg(short, long, value_delimiter = ',')] |
| 11 | + pub config: Option<Vec<PathBuf>>, |
12 | 12 |
|
13 | 13 | /// Path to the workspace directory |
14 | | - #[structopt(parse(from_os_str))] |
15 | | - pub workspace: std::path::PathBuf, |
| 14 | + pub workspace: PathBuf, |
16 | 15 |
|
17 | 16 | /// Comma separated list of ignore patterns. |
18 | 17 | /// Patterns must follow glob syntax |
19 | | - #[structopt(short, long, use_delimiter = true)] |
| 18 | + #[arg(short, long, value_delimiter = ',')] |
20 | 19 | pub ignore: Option<Vec<String>>, |
21 | 20 |
|
22 | 21 | /// Specify output format |
23 | | - #[structopt( |
24 | | - long, |
25 | | - default_value = "text", |
26 | | - possible_values = &OutputFormat::variants(), |
27 | | - case_insensitive = true |
28 | | - )] |
| 22 | + #[arg(long, default_value = "text", value_enum, ignore_case = true)] |
29 | 23 | pub output_format: OutputFormat, |
30 | 24 |
|
31 | 25 | /// Specify output destination (stdout or a file path, only used when output_format is json). |
32 | | - #[structopt(long, default_value = "stdout", parse(try_from_str))] |
| 26 | + #[arg(long, default_value = "stdout")] |
33 | 27 | pub output: OutputDestination, |
34 | 28 |
|
35 | 29 | /// Treat warnings as errors |
36 | | - #[structopt(long)] |
| 30 | + #[arg(long)] |
37 | 31 | pub warnings_as_errors: bool, |
38 | 32 |
|
39 | 33 | /// Verbose output |
40 | | - #[structopt(long)] |
| 34 | + #[arg(long)] |
41 | 35 | pub verbose: bool, |
42 | 36 | } |
43 | 37 |
|
44 | | -#[derive(Debug, Clone, PartialEq)] |
| 38 | +#[derive(Debug, Clone, PartialEq, ValueEnum)] |
45 | 39 | pub enum OutputFormat { |
46 | 40 | Json, |
47 | 41 | Text, |
48 | 42 | } |
49 | 43 |
|
50 | | -impl std::str::FromStr for OutputFormat { |
51 | | - type Err = String; |
52 | | - fn from_str(s: &str) -> Result<Self, Self::Err> { |
53 | | - match s.to_lowercase().as_str() { |
54 | | - "json" => Ok(OutputFormat::Json), |
55 | | - "text" => Ok(OutputFormat::Text), |
56 | | - _ => Err(format!("Invalid output format: {}", s)), |
57 | | - } |
58 | | - } |
59 | | -} |
60 | | - |
61 | | -impl OutputFormat { |
62 | | - pub fn variants() -> [&'static str; 2] { |
63 | | - ["json", "text"] |
64 | | - } |
65 | | -} |
66 | | - |
67 | 44 | #[allow(unused)] |
68 | 45 | #[derive(Debug, Clone)] |
69 | 46 | pub enum OutputDestination { |
70 | 47 | Stdout, |
71 | | - File(std::path::PathBuf), |
| 48 | + File(PathBuf), |
72 | 49 | } |
73 | 50 |
|
74 | 51 | impl std::str::FromStr for OutputDestination { |
75 | 52 | type Err = String; |
76 | 53 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
77 | 54 | match s.to_lowercase().as_str() { |
78 | 55 | "stdout" => Ok(OutputDestination::Stdout), |
79 | | - _ => Ok(OutputDestination::File(std::path::PathBuf::from(s))), |
| 56 | + _ => Ok(OutputDestination::File(PathBuf::from(s))), |
80 | 57 | } |
81 | 58 | } |
82 | 59 | } |
0 commit comments