korasi_cli/opt.rs
1use clap::{Parser, Subcommand};
2
3use crate::ec2::GLOBAL_TAG_FILTER;
4
5#[derive(Debug, Parser)]
6#[command(version, arg_required_else_help = true)]
7pub struct Opt {
8 /// AWS credentials profile to use (set in ~/.aws/credentials).
9 #[structopt(short, long, default_value = "default")]
10 pub profile: String,
11
12 /// Select region where ec2 instance is located.
13 #[structopt(short, long, default_value = "ap-southeast-1")]
14 pub region: String,
15
16 /// Configure common tag for all resources generated by this tool.
17 #[structopt(short, long, default_value = GLOBAL_TAG_FILTER)]
18 pub tag: Option<String>,
19
20 /// Enable to show logs.
21 #[structopt(short, default_value_t = false)]
22 pub debug: bool,
23
24 /// Specify path to launch script.
25 #[structopt(long, default_value = "start_up.sh")]
26 pub setup: String,
27
28 /// Path to SSH private key (default Ed25519).
29 /// Default path is set to $HOME/.ssh/{pk}.
30 ///
31 /// For now, other key types are not handled at the moment.
32 #[structopt(short, long)]
33 pub ssh_key: Option<String>,
34
35 #[command(subcommand)]
36 pub commands: Commands,
37}
38
39#[derive(Debug, Subcommand)]
40pub enum Commands {
41 /// Create new instance, and print out host.
42 ///
43 /// If not machine_type is specified, allow user to
44 /// choose machine_type from list of options.
45 Create { ami_id: String },
46
47 /// List all instances created by this tool, which is under
48 /// the same tag.
49 #[clap(alias = "ls")]
50 List,
51
52 /// Delete 1 or more instances, where all options are displayed
53 /// using a multi-select input.
54 Delete {
55 #[arg(long, short, default_value_t = true)]
56 wait: bool,
57 },
58
59 /// Start 1 or more instances.
60 ///
61 /// Starting a stopped instance without an EIP will
62 /// result in a new IP being assigned.
63 Start,
64
65 /// Stop 1 or more instances.
66 Stop {
67 #[arg(long, short)]
68 wait: bool,
69 },
70
71 /// Upload local file(s) or directory to remote target instance directory.
72 ///
73 /// Uses SFTP that rides on top of SSH to transfer files.
74 Upload {
75 /// Local relative/absolute path to file(s) or directory.
76 ///
77 /// If no `src` is specified, then files within with current
78 /// working directory will be uploaded to $HOME of remote.
79 #[arg(index = 1)]
80 src: Option<String>,
81
82 /// Destination folder path on remote instance to upload files to.
83 ///
84 /// Destination folder(s) must exist, otherwise you have to manually
85 /// create them using the `run` subcommand.
86 ///
87 /// If no dst is specified, files will be uploaded the $HOME/root
88 /// directory of remote. Root folder will be auto-created.
89 #[arg(index = 2)]
90 dst: Option<String>,
91
92 /// Specify user for OS distro.
93 #[arg(short, long, default_value = "ubuntu")]
94 user: String,
95 },
96
97 /// Executes a given command on remote instance.
98 /// Warn: output is not printed on centos distro (there may be more).
99 ///
100 /// Only run commands that are non-blocking. Commands like
101 /// opening `vi` does not working at the moment.
102 ///
103 /// TODO: run cmd from target directory.
104 #[clap(alias = "r")]
105 Run {
106 /// Specify user for OS distro.
107 #[arg(short, long, default_value = "ubuntu")]
108 user: String,
109
110 #[arg(allow_hyphen_values = true)]
111 command: Vec<String>,
112 },
113
114 /// SSH into instance.
115 ///
116 /// Executes default `bash` shell.
117 #[clap(alias = "sh")]
118 Shell {
119 /// Specify user for OS distro.
120 #[arg(short, long, default_value = "ubuntu")]
121 user: String,
122 },
123
124 /// Terminate all resources deployed by tool.
125 /// Does not remove AWS iAM permissions.
126 ///
127 /// Yugi: "I have assembled all the 5 pieces of Exodia. Exodia obliterate!"
128 Obliterate,
129}