1use std::path::PathBuf;
2
3use clap::{Command, command, arg, value_parser};
4
5pub fn cmd() -> Command {
7 command!()
8 .subcommands([
9 Command::new("doas")
11 .about("Run a command as a different user, default is root")
12 .defer(|cmd| {
13 cmd.args(&[
14 arg!(command: <COMMAND> ... "Command to run")
15 .required(true)
16 .value_parser(value_parser!(String)),
17
18 arg!(user: -u -user <USER> "Arguments to pass to command")
19 .required(false)
20 .value_parser(value_parser!(String)),
21
22 arg!(config: -C --config [config] "Path to config file")
23 .required(false)
24 .value_parser(value_parser!(PathBuf)),
25 ])
26 }),
27
28 Command::new("doasedit")
29 .about("Edit a file as a different user"),
30
31 Command::new("vidoas")
32 .about("visual editor in doas"),
33 ])
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_cli() {
42 let matches = cmd().get_matches_from("doas ls -l".split_ascii_whitespace());
43 assert_eq!(matches.subcommand_name(), Some("doas"));
44 }
45}