grant/cli.rs
1use std::path::PathBuf;
2use structopt::StructOpt;
3
4#[derive(Debug)]
5pub struct CustomError(String);
6
7/// Manage database roles and privileges in GitOps style
8#[derive(Debug, StructOpt)]
9pub struct Cli {
10 #[structopt(subcommand)]
11 pub cmd: Command,
12}
13
14#[derive(StructOpt, Debug)]
15pub enum Command {
16 /// Generate sample configuration file
17 Gen {
18 /// The target folder
19 #[structopt(short, long, default_value = ".", parse(from_os_str))]
20 target: PathBuf,
21 },
22
23 /// Generate random password
24 GenPass {
25 /// The target folder
26 #[structopt(short, long, default_value = "32")]
27 length: u8,
28 /// No special characters
29 #[structopt(short, long)]
30 no_special: bool,
31 /// The username, using to create md5 hash
32 #[structopt(short, long)]
33 username: Option<String>,
34 /// The password, using to create md5 hash
35 #[structopt(short, long)]
36 password: Option<String>,
37 },
38
39 /// Apply a configuration to a redshift by file name.
40 /// Yaml format are accepted.
41 Apply {
42 /// The path to the file to read, directory is not supported yet.
43 #[structopt(short, long, parse(from_os_str))]
44 file: PathBuf,
45
46 /// Dry run mode, only print what would be apply
47 #[structopt(short, long)]
48 dryrun: bool,
49
50 /// Apply all files in the current folder or target folder (if --file is a folder)
51 #[structopt(short, long)]
52 all: bool,
53 },
54
55 /// Validate a configuration file or
56 /// a target directory that contains configuration files
57 Validate {
58 /// The path to the file or directory
59 /// If the target is not available, the current
60 /// directory will be used.
61 #[structopt(short, long, parse(from_os_str))]
62 file: Option<PathBuf>,
63 },
64
65 /// Inspect current database cluster
66 /// with connection info from configuration file
67 Inspect {
68 /// The path to the file to read
69 #[structopt(short, long, parse(from_os_str))]
70 file: PathBuf,
71 },
72}
73
74// Parse the command line arguments
75pub fn parse() -> Cli {
76 Cli::from_args()
77}