1use clap::{Args, Parser, Subcommand};
2use regex::Regex;
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6#[derive(Serialize, Deserialize, Debug)]
7pub struct GcpConfig {
8 pub project_id: String,
9 pub service_name: String,
10 pub region: String,
11 pub network: String,
12}
13
14fn regex(re_str: &str) -> Regex {
15 Regex::new(re_str).unwrap()
16}
17
18impl GcpConfig {
19 pub fn gcr_region(&self) -> &str {
20 let asia = regex("asia");
21 let eu = regex("europe");
22 return if asia.is_match(&self.region) {
23 "asia.gcr.io"
24 } else if eu.is_match(&self.region) {
25 "eu.gcr.io"
26 } else {
27 "gcr.io"
28 };
29 }
30}
31
32#[derive(Parser)]
33#[clap(name = "zapp")]
34#[clap(about = "Rust Serverless Framework")]
35#[clap(author = "EpicsDAO", version, long_about = None)]
36pub struct Cli {
37 #[clap(subcommand)]
38 pub command: Commands,
39}
40
41#[derive(Subcommand)]
42pub enum Commands {
43 Iam(Iam),
44 Run(Run),
45 Gh(Gh),
46 Init(Init),
47 Compute(Compute),
48 Docker(Docker),
49 Sql(Sql),
50 G(G),
51 Db(Db),
52 New { app_name: String },
53 Gcloud(Gcloud),
54}
55
56#[derive(Debug, Args)]
57#[clap(args_conflicts_with_subcommands = true)]
58pub struct Iam {
59 #[clap(subcommand)]
60 pub command: Option<IamCommands>,
61}
62
63#[derive(Debug, Args)]
64#[clap(args_conflicts_with_subcommands = true)]
65pub struct Compute {
66 #[clap(subcommand)]
67 pub command: Option<ComputeCommands>,
68}
69
70#[derive(Debug, Args)]
71#[clap(args_conflicts_with_subcommands = true)]
72pub struct Init {
73 #[clap(subcommand)]
74 pub command: Option<InitCommands>,
75}
76
77#[derive(Debug, Args)]
78#[clap(args_conflicts_with_subcommands = true)]
79pub struct Gh {
80 #[clap(subcommand)]
81 pub command: Option<GhCommands>,
82}
83
84#[derive(Debug, Args)]
85#[clap(args_conflicts_with_subcommands = true)]
86pub struct Run {
87 #[clap(subcommand)]
88 pub command: Option<RunCommands>,
89}
90
91#[derive(Debug, Args)]
92#[clap(args_conflicts_with_subcommands = true)]
93pub struct Docker {
94 #[clap(subcommand)]
95 pub command: Option<DockerCommands>,
96}
97
98#[derive(Debug, Args)]
99#[clap(args_conflicts_with_subcommands = true)]
100pub struct Sql {
101 #[clap(subcommand)]
102 pub command: Option<SqlCommands>,
103}
104
105#[derive(Debug, Args)]
106#[clap(args_conflicts_with_subcommands = true)]
107pub struct G {
108 #[clap(subcommand)]
109 pub command: Option<GCommands>,
110}
111
112#[derive(Debug, Args)]
113#[clap(args_conflicts_with_subcommands = true)]
114pub struct Db {
115 #[clap(subcommand)]
116 pub command: Option<DbCommands>,
117}
118
119#[derive(Debug, Args)]
120#[clap(args_conflicts_with_subcommands = true)]
121pub struct Gcloud {
122 #[clap(subcommand)]
123 pub command: Option<GcloudCommands>,
124}
125
126#[derive(Debug, Subcommand)]
127pub enum IamCommands {
128 Setup,
129 Help,
130}
131
132#[derive(Debug, Subcommand)]
133pub enum ComputeCommands {
134 CreateNat,
135 Help,
136}
137
138#[derive(Debug, Subcommand)]
139pub enum InitCommands {
140 Config,
141 GhActions,
142 Help,
143}
144
145#[derive(Debug, Subcommand)]
146pub enum GhCommands {
147 AddEnv,
148 Help,
149}
150
151#[derive(Debug, Subcommand)]
152pub enum RunCommands {
153 Build,
154 Deploy,
155 Help,
156}
157
158#[derive(Debug, Subcommand)]
159pub enum DockerCommands {
160 Psql,
161 Build,
162 Restart,
163 Push,
164 Help,
165}
166
167#[derive(Debug, Subcommand)]
168pub enum SqlCommands {
169 Create,
170 Patch { action: String },
171 Restart,
172 SetPrivateIp,
173 Help,
174}
175
176#[derive(Debug, Subcommand)]
177pub enum GCommands {
178 Model {
179 model: String,
180 #[clap(parse(from_os_str), short, long)]
181 path: Option<PathBuf>,
182 },
183 Help,
184}
185
186#[derive(Debug, Subcommand)]
187pub enum DbCommands {
188 Migrate,
189 Reset,
190 Refresh,
191 Rollback,
192 Help,
193}
194
195#[derive(Debug, Subcommand)]
196pub enum GcloudCommands {
197 Setup,
198 Help,
199}