emmylua_doc_cli/
cmd_args.rs

1use clap::{Parser, ValueEnum};
2use std::path::PathBuf;
3
4#[derive(Debug, Parser)]
5#[command(version)]
6pub struct CmdArgs {
7    /// Configuration file paths.
8    /// If not provided, both ".emmyrc.json" and ".luarc.json" will be searched in the workspace
9    /// directory
10    #[arg(short, long, value_delimiter = ',')]
11    pub config: Option<Vec<PathBuf>>,
12
13    /// Deprecated, use [WORKSPACE] instead
14    #[arg(short, long, num_args = 1..)]
15    pub input: Vec<PathBuf>,
16
17    /// Path to the workspace directory
18    #[arg(num_args = 1..)]
19    pub workspace: Vec<PathBuf>,
20
21    /// Comma separated list of ignore patterns.
22    /// Patterns must follow glob syntax
23    #[arg(long, value_delimiter = ',')]
24    pub ignore: Option<Vec<String>>,
25
26    /// Specify output format
27    #[arg(
28        long,
29        short = 'f',
30        default_value = "markdown",
31        value_enum,
32        ignore_case = true
33    )]
34    pub output_format: Format,
35
36    /// Deprecated, use --output-format instead
37    #[arg(long, value_enum, ignore_case = true)]
38    pub format: Option<Format>,
39
40    /// Specify output destination (can be stdout when output_format is json)
41    #[arg(long, short, default_value = "./output")]
42    pub output: OutputDestination,
43
44    /// The path of the override template
45    #[arg(long)]
46    pub override_template: Option<PathBuf>,
47
48    #[arg(long, default_value = "Docs")]
49    pub site_name: Option<String>,
50
51    /// A directory whose contents are merged with the generated Markdown files.
52    /// For example, to override docs/index.md, create a folder called "docs" in
53    /// your mixin folder and create a file called "index.md" inside it.
54    #[arg(long)]
55    pub mixin: Option<PathBuf>,
56
57    /// Verbose output
58    #[arg(long)]
59    pub verbose: bool,
60}
61
62#[derive(Debug, Clone, Eq, PartialEq, ValueEnum)]
63pub enum Format {
64    Json,
65    Markdown,
66}
67
68#[allow(unused)]
69#[derive(Debug, Clone)]
70pub enum OutputDestination {
71    Stdout,
72    File(PathBuf),
73}
74
75impl std::str::FromStr for OutputDestination {
76    type Err = String;
77    fn from_str(s: &str) -> Result<Self, Self::Err> {
78        match s.to_lowercase().as_str() {
79            "stdout" => Ok(OutputDestination::Stdout),
80            _ => Ok(OutputDestination::File(PathBuf::from(s))),
81        }
82    }
83}