composition_cli/context/
cli.rs1use clap::Parser;
2use std::path::{Path, PathBuf};
3
4#[derive(Debug, Parser)]
5#[command(author = "lalitm1004")]
6pub struct Cli {
7 #[arg(
8 default_value = ".",
9 value_parser = parse_path,
10 value_name = "PATH",
11 help = "Path to the directory of file to process"
12 )]
13 pub path: PathBuf,
14
15 #[arg(
16 long,
17 global = true,
18 default_value_t = 1.0,
19 value_parser = parse_scale_bar,
20 value_name = "FLOAT",
21 help = "Scale factor for the contribution bar"
22 )]
23 pub scale_bar: f32,
24
25 #[arg(long, help = "Override use_color config setting")]
26 pub use_color: Option<bool>,
27
28 #[arg(long, help = "Override respect_gitignore config setting")]
29 pub respect_gitignore: Option<bool>,
30
31 #[arg(long, help = "Override ignore_dotfolders config setting")]
32 pub ignore_dotfolders: Option<bool>,
33
34 #[arg(long, help = "Override ignore_dotfiles config setting")]
35 pub ignore_dotfiles: Option<bool>,
36
37 #[arg(long, help = "Override ignore_empty_lines config setting")]
38 pub ignore_empty_lines: Option<bool>,
39}
40
41fn parse_path(arg: &str) -> Result<PathBuf, String> {
42 let path = Path::new(arg);
43 if path.exists() {
44 Ok(path.to_path_buf())
45 } else {
46 Err(format!(
47 "invalid value '{}' for [PATH]: does not exist",
48 arg
49 ))
50 }
51}
52
53fn parse_scale_bar(arg: &str) -> Result<f32, String> {
54 arg.parse::<f32>().map_err(|_| {
55 format!(
56 "invalid value '{}' for [SCALE_BAR]: must be a valid floating-point value",
57 arg
58 )
59 })
60}