1use clap::{Arg, ArgAction, ArgMatches, Command, SubCommand};
2use std::string::String;
3
4const PROGRAM_DESC: &str = "Convenient utils for saving and install dotfiles";
5const PROGRAM_NAME: &str = "dotfiles";
6
7pub fn command() -> Result<ArgMatches, String> {
8 let cli: Command = Command::new(PROGRAM_NAME)
9 .version("0.1.0")
10 .author("Douglas Wu <wckdouglas@gmail.com>")
11 .about(PROGRAM_DESC)
12 .arg(
13 Arg::with_name("dotfile_yaml")
14 .help("A yaml file containing the dotfile names (see data/dotfiles.yaml)")
15 .long("dotfile-yaml")
16 .short('y')
17 .takes_value(true)
18 .required(true),
19 )
20 .subcommand(
21 SubCommand::with_name("save")
24 .about("Save dotfiles into a folder")
25 .arg(
26 Arg::with_name("dest_dir")
27 .help("The destination directory to save for copying the dotfiles to")
28 .short('d')
29 .long("dest-dir")
30 .takes_value(true)
31 .required(true),
32 )
33 .arg(
34 Arg::with_name("dry")
35 .help("Dry run")
36 .long("dry-run")
37 .takes_value(false)
38 .required(false)
39 .action(ArgAction::SetTrue),
40 )
41 )
42 .subcommand(
43 SubCommand::with_name("apply-gh")
44 .about("Applying dotfiles from a github url")
47 .arg(
48 Arg::with_name("url")
49 .help("The github url")
50 .short('u')
51 .long("url")
52 .takes_value(true)
53 .required(true),
54 )
55 .arg(
56 Arg::with_name("ssh_key")
57 .help("The ssh key to use, the private key file, should have a .pub file in the same folder too (default: ~/.ssh/id_rsa)")
58 .short('s')
59 .long("ssh-key")
60 .takes_value(true)
61 .required(false)
62 )
63 .arg(
64 Arg::with_name("dry")
65 .help("Dry run")
66 .long("dry-run")
67 .short('n')
68 .takes_value(false)
69 .required(false)
70 .action(ArgAction::SetTrue)
71 ),
72 )
73 .subcommand(
74 SubCommand::with_name("apply")
75 .about("Applying dotfiles from a cloned dotfiles dir")
78 .arg(
79 Arg::with_name("dir")
80 .help("The directory to dotfiles")
81 .short('d')
82 .long("dir")
83 .takes_value(true)
84 .required(true),
85 )
86 .arg(
87 Arg::with_name("dry")
88 .help("Dry run")
89 .long("dry-run")
90 .short('n')
91 .takes_value(false)
92 .required(false)
93 .action(ArgAction::SetTrue)
94 ),
95 );
96
97 Ok(cli.get_matches())
98}