1use crate::app::banner::BANNERS;
4use crate::app::selection::Selection;
5use crate::app::style::Style;
6use crate::gpg::key::KeyDetail;
7use crate::widget::style::Color;
8use clap::Parser;
9
10#[derive(Debug, Default, Parser)]
12#[clap(
13 version,
14 author = clap::crate_authors!("\n"),
15 about,
16 rename_all_env = "screaming-snake",
17 before_help = format!("\u{2800} {}", BANNERS[2]),
18 help_template = "\
19{before-help}{name} {version}
20{author-with-newline}{about-with-newline}
21{usage-heading}
22 {usage}
23
24{all-args}{after-help}
25",
26)]
27pub struct Args {
28 #[clap(short, long)]
30 pub armor: bool,
31 #[clap(long)]
33 pub splash: bool,
34 #[clap(
36 long,
37 value_name = "path",
38 env = "GPG_TUI_CONFIG",
39 value_parser = Args::parse_dir
40 )]
41 pub config: Option<String>,
42 #[clap(
44 long,
45 value_name = "dir",
46 env = "GNUPGHOME",
47 value_parser = Args::parse_dir
48 )]
49 pub homedir: Option<String>,
50 #[clap(
52 short,
53 long,
54 value_name = "dir",
55 env,
56 value_parser = Args::parse_dir
57 )]
58 pub outdir: Option<String>,
59 #[clap(
61 long,
62 value_name = "path",
63 default_value = "{type}_{query}.{ext}",
64 env,
65 value_parser = Args::parse_dir
66 )]
67 pub outfile: String,
68 #[clap(short, long, value_name = "key", env)]
70 pub default_key: Option<String>,
71 #[clap(short, long, value_name = "ms", default_value = "250", env)]
73 pub tick_rate: u64,
74 #[clap(short, long, value_name = "color", default_value = "gray", env)]
76 pub color: Color,
77 #[clap(short, long, value_name = "style", default_value = "colored", env)]
79 pub style: Style,
80 #[clap(short, long, value_name = "app", default_value = "xplr", env)]
82 pub file_explorer: String,
83 #[clap(long, value_name = "level", default_value = "minimum", env)]
85 pub detail_level: KeyDetail,
86 #[clap(long, value_name = "path", env)]
88 pub log_file: Option<String>,
89 #[clap(long, value_name = "option", env)]
91 pub select: Option<Selection>,
92}
93
94impl Args {
95 fn parse_dir(dir: &str) -> Result<String, String> {
102 Ok(shellexpand::tilde(dir).to_string())
103 }
104}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109 use clap::CommandFactory;
110 use std::path::PathBuf;
111 #[test]
112 fn test_args() {
113 Args::command().debug_assert();
114 }
115 #[test]
116 fn test_tilde_expansion() {
117 let home_dir =
118 dirs_next::home_dir().expect("cannot retrieve home directory");
119 let dir = Args::parse_dir("~/").expect("cannot expand tilde");
120 assert_eq!(home_dir, PathBuf::from(dir));
121 }
122}