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 /// Delete database users that exist in DB but not in config (GitOps mode)
55 /// WARNING: This is a destructive operation. Users will be permanently deleted.
56 #[structopt(long)]
57 delete_users: bool,
58 },
59
60 /// Validate a configuration file or
61 /// a target directory that contains configuration files
62 Validate {
63 /// The path to the file or directory
64 /// If the target is not available, the current
65 /// directory will be used.
66 #[structopt(short, long, parse(from_os_str))]
67 file: Option<PathBuf>,
68 },
69
70 /// Inspect current database cluster
71 /// with connection info from configuration file
72 Inspect {
73 /// The path to the file to read
74 #[structopt(short, long, parse(from_os_str))]
75 file: PathBuf,
76 },
77}
78
79// Parse the command line arguments
80pub fn parse() -> Cli {
81 Cli::from_args()
82}