1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
pub mod add;
pub mod admin;
pub mod build;
pub mod cloudflare;
pub mod cron;
pub mod deploy;
pub mod destroy;
pub mod dev;
pub mod domain;
pub mod env;
pub mod fe_runtime;
pub mod init;
pub mod login;
pub mod open;
pub mod project_config;
pub mod purge;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "forte")]
#[command(about = "Forte - Fullstack Framework", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
Dev {
#[arg(short, long)]
project: Option<PathBuf>,
#[arg(short = 'P', long)]
port: Option<u16>,
},
Init {
name: String,
#[arg(long)]
dev: bool,
},
Login {
#[arg(long)]
token: Option<String>,
},
Add {
#[command(subcommand)]
command: AddCommands,
},
Build {
#[arg(short, long)]
project: Option<PathBuf>,
},
Deploy {
#[arg(short, long)]
project: Option<PathBuf>,
#[arg(long)]
name: Option<String>,
},
/// Delete the deployed project and all of its resources
Destroy {
#[arg(long)]
yes: bool,
},
/// Print the deployed app URL and open it in the browser
Open {
#[arg(short, long)]
project: Option<PathBuf>,
/// Print the URL without opening a browser
#[arg(long)]
print: bool,
},
/// Invalidate the edge copy of public objects
Purge {
/// Keys inside the project's public namespace, e.g. captures/1/0.mp4
#[arg(required = true)]
keys: Vec<String>,
#[arg(short, long)]
project: Option<PathBuf>,
},
Admin {
#[command(subcommand)]
command: AdminCommands,
},
Domain {
#[command(subcommand)]
command: DomainCommands,
},
/// Run this project's storage, CDN and custom domain on your own
/// Cloudflare account
Cloudflare {
#[command(subcommand)]
command: CloudflareCommands,
},
Env {
#[command(subcommand)]
command: EnvCommands,
},
}
#[derive(Subcommand)]
pub enum EnvCommands {
/// Set an env entry (plain by default, encrypted when --secret)
Set {
key: String,
value: String,
#[arg(long)]
secret: bool,
#[arg(short, long)]
project: Option<PathBuf>,
},
/// Convert a legacy .env file into env.local.yaml
Migrate {
#[arg(short, long)]
project: Option<PathBuf>,
},
}
#[derive(Subcommand)]
pub enum DomainCommands {
/// Attach a custom domain to this project
Add {
domain: String,
/// Required for a project on your own Cloudflare account: the origin
/// certificate is signed here, because fn0 holds no token that can
/// sign one
#[arg(long)]
account_id: Option<String>,
#[arg(long)]
zone_id: Option<String>,
/// Either a token with SSL and Certificates Edit, or one with User ->
/// API Tokens -> Edit plus --mint-signing-token
#[arg(long)]
api_token: Option<String>,
/// Mint a short-lived signing token instead of signing with the token
/// directly. Needed when the token only carries API Tokens Edit.
#[arg(long)]
mint_signing_token: bool,
#[arg(short, long)]
project: Option<PathBuf>,
},
Remove {
#[arg(short, long)]
project: Option<PathBuf>,
},
Status {
#[arg(short, long)]
project: Option<PathBuf>,
},
}
#[derive(Subcommand)]
pub enum CloudflareCommands {
/// Connect this project to your Cloudflare account
///
/// Two ways in. With --api-token the CLI provisions your account and mints
/// the credentials fn0 keeps; that token needs only User -> API Tokens ->
/// Edit, but a token that can create tokens can create any token, so it is
/// account-wide until you delete it.
///
/// If you would rather never create such a token, run `forte cloudflare
/// provision` first and pass the credentials you made yourself here
/// instead.
Connect {
#[arg(long)]
account_id: String,
#[arg(long)]
zone_id: String,
/// Token with User -> API Tokens -> Edit. Provisions and mints.
#[arg(long, conflicts_with_all = ["zone_name", "dataplane_access_key_id"])]
api_token: Option<String>,
/// Credentials you created yourself, after `forte cloudflare provision`
#[arg(long, requires_all = ["dataplane_access_key_id", "dataplane_secret", "purge_token"])]
zone_name: Option<String>,
#[arg(long)]
dataplane_access_key_id: Option<String>,
#[arg(long)]
dataplane_secret: Option<String>,
#[arg(long)]
purge_token: Option<String>,
#[arg(short, long)]
project: Option<PathBuf>,
},
/// Create the buckets, CDN hostname and cache rule, and stop there
///
/// For people who would rather not hand any tool a token that can create
/// tokens. Use a token with Workers R2 Storage Edit, Zone Read, Cache Rules
/// Edit and SSL and Certificates Edit — it can provision but cannot create
/// tokens, so it cannot widen itself. The command then tells you which two
/// credentials to make by hand.
Provision {
#[arg(long)]
account_id: String,
#[arg(long)]
zone_id: String,
#[arg(long)]
api_token: String,
#[arg(short, long)]
project: Option<PathBuf>,
},
Status {
#[arg(short, long)]
project: Option<PathBuf>,
},
}
#[derive(Subcommand)]
pub enum AdminCommands {
Run {
task: String,
#[arg(short, long)]
project: Option<PathBuf>,
#[arg(long)]
input_file: Option<PathBuf>,
#[arg(long)]
input: Option<String>,
#[arg(long, default_value_t = 300)]
timeout_seconds: u64,
},
RunLocal {
task: String,
#[arg(short = 'P', long, default_value_t = 3000)]
port: u16,
#[arg(long)]
input_file: Option<PathBuf>,
#[arg(long)]
input: Option<String>,
#[arg(long, default_value_t = 300)]
timeout_seconds: u64,
},
}
#[derive(Subcommand)]
pub enum AddCommands {
Page { path: String },
Action { path: String },
}