tex_fmt/
command.rs

1use clap::{value_parser, Arg, ArgAction, Command};
2use std::path::PathBuf;
3use ArgAction::{Append, SetTrue};
4
5/// Construct the CLI command
6#[allow(clippy::too_many_lines)]
7#[must_use]
8pub fn get_cli_command() -> Command {
9    Command::new("tex-fmt")
10        .author("William George Underwood, wg.underwood13@gmail.com")
11        .about(clap::crate_description!())
12        .version(clap::crate_version!())
13        .before_help(format!("tex-fmt {}", clap::crate_version!()))
14        .arg(
15            Arg::new("check")
16                .short('c')
17                .long("check")
18                .action(SetTrue)
19                .help("Check formatting, do not modify files"),
20        )
21        .arg(
22            Arg::new("print")
23                .short('p')
24                .long("print")
25                .action(SetTrue)
26                .help("Print to stdout, do not modify files"),
27        )
28        .arg(
29            Arg::new("fail-on-change")
30                .short('f')
31                .long("fail-on-change")
32                .action(SetTrue)
33                .help("Format files and return non-zero exit code if files are modified")
34        )
35        .arg(
36            Arg::new("nowrap")
37                .short('n')
38                .long("nowrap")
39                .action(SetTrue)
40                .help("Do not wrap long lines"),
41        )
42        .arg(
43            Arg::new("wraplen")
44                .short('l')
45                .long("wraplen")
46                .value_name("N")
47                .value_parser(value_parser!(u8))
48                .help("Line length for wrapping [default: 80]"),
49        )
50        .arg(
51            Arg::new("tabsize")
52                .short('t')
53                .long("tabsize")
54                .value_name("N")
55                .value_parser(value_parser!(u8))
56                .help("Number of characters to use as tab size [default: 2]"),
57        )
58        .arg(
59            Arg::new("usetabs")
60                .long("usetabs")
61                .action(SetTrue)
62                .help("Use tabs instead of spaces for indentation"),
63        )
64        .arg(
65            Arg::new("stdin")
66                .short('s')
67                .long("stdin")
68                .action(SetTrue)
69                .help("Process stdin as a single file, output to stdout"),
70        )
71        .arg(
72            Arg::new("config")
73                .long("config")
74                .value_name("PATH")
75                .value_parser(value_parser!(PathBuf))
76                .help("Path to config file")
77        )
78        .arg(
79            Arg::new("noconfig")
80                .long("noconfig")
81                .action(SetTrue)
82                .help("Do not read any config file"),
83        )
84        .arg(
85            Arg::new("verbose")
86                .short('v')
87                .long("verbose")
88                .action(SetTrue)
89                .help("Show info messages"),
90        )
91        .arg(
92            Arg::new("quiet")
93                .short('q')
94                .long("quiet")
95                .action(SetTrue)
96                .help("Hide warning messages"),
97        )
98        .arg(
99            Arg::new("trace")
100                .long("trace")
101                .action(SetTrue)
102                .help("Show trace messages"),
103        )
104        .arg(
105            Arg::new("completion")
106                .long("completion")
107                .value_name("SHELL")
108                .value_parser(value_parser!(Shell))
109                .help("Generate shell completion script")
110        )
111        .arg(
112            Arg::new("man")
113                .long("man")
114                .action(SetTrue)
115                .help("Generate man page"),
116        )
117        .arg(
118            Arg::new("args")
119                .long("args")
120                .action(SetTrue)
121                .help("Print arguments passed to tex-fmt and exit"),
122        )
123        .arg(
124            Arg::new("files")
125                .action(Append)
126                .help("List of files to be formatted"),
127        )
128        .arg(
129            Arg::new("recursive")
130                .short('r')
131                .long("recursive")
132                .action(SetTrue)
133                .help("Recursively search for files to format")
134        )
135}