-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmdline.rs
52 lines (43 loc) · 1.43 KB
/
cmdline.rs
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
use std::{path::PathBuf, str::FromStr};
use argh::FromArgs;
#[derive(Debug, FromArgs)]
/// Index top-level definitions found in Agda modules rendered to HTML
pub struct CommandLine {
#[argh(option, default = "OutputFormat::Plain")]
/// textual format of the finished index.
/// Either
/// "plain" (space-separated plaintext, default),
/// "json" (JSON dictionary {{<source file>: <module items>}}), or
/// "docset" (a Dash Docset)
pub output_format: OutputFormat,
#[argh(option, default = r#"("agda".into())"#)]
/// name of the Agda library (field `name` in .agda-lib)
pub library_name: String,
#[argh(option, default = r#"("index.html".into())"#)]
/// path to the main page, relative to <html_dir> (default: index.html)
pub main_page: PathBuf,
#[argh(positional)]
/// paths to directory containing HTML files of rendered Agda modules
pub html_dir: PathBuf,
}
#[derive(Debug, Clone, Copy)]
pub enum OutputFormat {
Plain,
Json,
Docset,
}
impl FromStr for OutputFormat {
type Err = &'static str;
fn from_str(fmt: &str) -> Result<Self, Self::Err> {
match fmt {
"plain" => Ok(Self::Plain),
"json" => Ok(Self::Json),
"docset" => Ok(Self::Docset),
_ => Err("expected one of 'plain', 'json' or 'docset'"),
}
}
}
/// Parse arguments given on the command line.
pub fn parse() -> CommandLine {
argh::from_env()
}