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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use reqwest::Client;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
// Module declarations with feature gates
#[cfg(feature = "cli")]
mod api;
#[cfg(feature = "cli")]
mod build;
#[cfg(feature = "cli")]
mod cli;
#[cfg(feature = "backend")]
mod db;
#[cfg(feature = "backend")]
mod server;
// Re-export for convenience (CLI modules)
#[cfg(feature = "cli")]
use cli::*;
/// Resolve project name from explicit argument or rise.toml fallback
#[cfg(feature = "cli")]
fn resolve_project_name(explicit_project: Option<String>, path: &str) -> Result<String> {
if let Some(project) = explicit_project {
Ok(project)
} else if let Some(config) = build::config::load_full_project_config(path)? {
if let Some(project_config) = config.project {
Ok(project_config.name)
} else {
anyhow::bail!("No project name specified and rise.toml has no [project] section")
}
} else {
anyhow::bail!("No project name specified and no rise.toml found")
}
}
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
command: Commands,
}
/// Shared arguments for deployment creation
#[derive(Debug, Clone, clap::Args)]
struct DeployArgs {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to the directory containing the application (defaults to current directory)
#[arg(default_value = ".")]
path: String,
/// Pre-built image to deploy (e.g., nginx:latest). Skips build if provided.
#[arg(long, short)]
image: Option<String>,
/// Create deployment from an existing deployment (e.g., '20240101-120000'). Skips build and reuses the image.
#[arg(long)]
from: Option<String>,
/// When used with --from, copy environment variables from source deployment instead of using current project vars
#[arg(long)]
use_source_env_vars: bool,
/// Deployment group (e.g., 'default', 'mr/27'). Defaults to 'default' if not specified.
#[arg(long, short)]
group: Option<String>,
/// Expiration duration (e.g., '7d', '2h', '30m'). Deployment will be automatically cleaned up after this period.
#[arg(long)]
expire: Option<String>,
/// HTTP port the application listens on (e.g., 3000, 8080, 5000).
/// Required when using --image. Defaults to 8080 for buildpack builds.
#[arg(long)]
http_port: Option<u16>,
#[command(flatten)]
build_args: build::BuildArgs,
}
#[derive(Subcommand, Debug)]
enum Commands {
/// Backend server and controller commands
#[command(subcommand)]
Backend(backend::BackendCommands),
/// Build a container image locally without deploying
Build {
/// Tag for the built image (e.g., myapp:latest, registry.io/org/app:v1.0)
tag: String,
/// Path to the directory containing the application
#[arg(default_value = ".")]
path: String,
/// Push image to registry after building
#[arg(long)]
push: bool,
#[command(flatten)]
build_args: build::BuildArgs,
},
/// Deploy an application (shortcut for 'deployment create')
Deploy {
#[command(flatten)]
args: DeployArgs,
},
/// Deployment management commands
#[command(subcommand)]
#[command(visible_alias = "d")]
Deployment(DeploymentCommands),
/// Custom domain management commands
#[command(subcommand)]
#[command(visible_alias = "dom")]
Domain(DomainCommands),
/// Encrypt a secret for use in extension specs
Encrypt {
/// Secret to encrypt (or read from stdin if not provided)
plaintext: Option<String>,
},
/// Environment variable management commands
#[command(subcommand)]
#[command(visible_alias = "e")]
Env(EnvCommands),
/// Extension management commands
#[command(subcommand)]
#[command(visible_alias = "ext")]
Extension(ExtensionCommands),
/// Authenticate with the Rise backend
Login {
/// Backend URL to authenticate with
#[arg(long)]
url: Option<String>,
/// Use browser-based OAuth2 authorization code flow (default)
#[arg(long, conflicts_with = "device")]
browser: bool,
/// Use device authorization flow
#[arg(long, conflicts_with = "browser")]
device: bool,
},
/// Project management commands
#[command(subcommand)]
#[command(visible_alias = "p")]
Project(ProjectCommands),
/// Build and run a container locally for development
Run {
/// Project name (optional, used to load environment variables)
#[arg(long, short)]
project: Option<String>,
/// Load environment variables from the associated Rise project (non-secret only). Defaults to true.
#[arg(long, default_value = "true", action = clap::ArgAction::Set)]
use_project_env: bool,
/// Path to the directory containing the application
#[arg(default_value = ".")]
path: String,
/// HTTP port the application listens on (also sets PORT env var)
#[arg(long, default_value = "8080")]
http_port: u16,
/// Port to expose on the host (defaults to same as http-port)
#[arg(long)]
expose: Option<u16>,
/// Runtime environment variables (format: KEY=VALUE, can be specified multiple times)
#[arg(long = "run-env", short, value_parser = parse_key_val::<String, String>)]
run_env: Vec<(String, String)>,
#[command(flatten)]
build_args: build::BuildArgs,
},
/// Service account (workload identity) management commands
#[command(subcommand)]
#[command(visible_alias = "sa")]
ServiceAccount(ServiceAccountCommands),
/// Team management commands
#[command(subcommand)]
#[command(visible_alias = "t")]
Team(TeamCommands),
}
/// Project creation mode
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum ProjectMode {
/// Create/update project on backend only
Remote,
/// Create/update rise.toml only (no backend interaction)
Local,
/// Create project on backend AND create rise.toml
#[value(name = "remote+local")]
RemoteLocal,
}
#[derive(Subcommand, Debug)]
enum ProjectCommands {
/// Create a new project
#[command(visible_alias = "c")]
#[command(visible_alias = "new")]
Create {
/// Project name (required for remote and remote+local modes, optional for local mode)
name: Option<String>,
/// Access class (e.g., public, private)
#[arg(long, default_value = "public")]
access_class: String,
/// Owner (format: "user:email" or "team:name", defaults to current user)
#[arg(long)]
owner: Option<String>,
/// Path where to create rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Mode: remote (backend only), local (rise.toml only), remote+local (both).
/// If unset: remote if rise.toml exists, remote+local otherwise
#[arg(long, value_enum)]
mode: Option<ProjectMode>,
},
/// List all projects
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {},
/// Show project details
#[command(visible_alias = "s")]
Show {
/// Project name
project: String,
},
/// Update project
#[command(visible_alias = "u")]
#[command(visible_alias = "edit")]
Update {
/// Project name
project: String,
/// New project name
#[arg(long)]
name: Option<String>,
/// New access class (e.g., public, private)
#[arg(long)]
access_class: Option<String>,
/// Transfer ownership (format: "user:email" or "team:name")
#[arg(long)]
owner: Option<String>,
/// Sync from rise.toml to backend (ignores other flags)
#[arg(long)]
sync: bool,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
/// Delete a project
#[command(visible_alias = "del")]
#[command(visible_alias = "rm")]
Delete {
/// Project name
project: String,
},
/// Manage app users/teams (view-only access to deployed apps)
#[command(subcommand)]
AppUser(AppUserCommands),
}
#[derive(Subcommand, Debug)]
enum AppUserCommands {
/// Add a user or team as an app user (view-only access to deployed app)
#[command(visible_alias = "a")]
Add {
/// Project name (optional if rise.toml contains [project] section)
project: Option<String>,
/// User or team identifier (format: "user:email" or "team:name")
identifier: String,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
/// Remove a user or team from app users
#[command(visible_alias = "rm")]
#[command(visible_alias = "del")]
Remove {
/// Project name (optional if rise.toml contains [project] section)
project: Option<String>,
/// User or team identifier (format: "user:email" or "team:name")
identifier: String,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
/// List all app users and teams
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {
/// Project name (optional if rise.toml contains [project] section)
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
}
#[derive(Subcommand, Debug)]
enum TeamCommands {
/// Create a new team
#[command(visible_alias = "c")]
#[command(visible_alias = "new")]
Create {
/// Team name
name: String,
/// Owner emails (comma-separated, defaults to current user)
#[arg(long)]
owners: Option<String>,
/// Member emails (comma-separated, optional)
#[arg(long, default_value = "")]
members: String,
},
/// List all teams
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {},
/// Show team details
#[command(visible_alias = "s")]
Show {
/// Team name
team: String,
},
/// Update team
#[command(visible_alias = "u")]
#[command(visible_alias = "edit")]
Update {
/// Team name
team: String,
/// New team name
#[arg(long)]
name: Option<String>,
/// Add owners (comma-separated email addresses)
#[arg(long)]
add_owners: Option<String>,
/// Remove owners (comma-separated email addresses)
#[arg(long)]
remove_owners: Option<String>,
/// Add members (comma-separated email addresses)
#[arg(long)]
add_members: Option<String>,
/// Remove members (comma-separated email addresses)
#[arg(long)]
remove_members: Option<String>,
},
/// Delete a team
#[command(visible_alias = "del")]
#[command(visible_alias = "rm")]
Delete {
/// Team name
team: String,
},
}
#[derive(Subcommand, Debug)]
#[allow(clippy::large_enum_variant)]
enum DeploymentCommands {
/// Create a new deployment
#[command(visible_alias = "c")]
#[command(visible_alias = "new")]
Create {
#[command(flatten)]
args: DeployArgs,
},
/// List deployments for a project
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Filter by deployment group
#[arg(long, short)]
group: Option<String>,
/// Limit number of deployments to show
#[arg(long, short, default_value = "10")]
limit: usize,
},
/// Show deployment details
#[command(visible_alias = "s")]
Show {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Deployment ID
deployment_id: String,
/// Follow deployment until completion
#[arg(long, short)]
follow: bool,
/// Timeout for following deployment
#[arg(long, default_value = "5m")]
timeout: String,
},
/// Stop all deployments in a group
Stop {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Deployment group to stop
#[arg(long, short)]
group: String,
},
/// Show logs from a deployment
Logs {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Deployment ID (YYYYMMDD-HHMMSS format)
deployment_id: String,
/// Follow log output (stream continuously)
#[arg(short, long)]
follow: bool,
/// Number of lines to show from end of logs
#[arg(long)]
tail: Option<usize>,
/// Show timestamps in log output
#[arg(long)]
timestamps: bool,
/// Show logs since duration (e.g., "5m", "1h")
#[arg(long)]
since: Option<String>,
},
}
#[derive(Subcommand, Debug)]
enum ServiceAccountCommands {
/// Create a new service account for a project
#[command(visible_alias = "c")]
#[command(visible_alias = "new")]
Create {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// OIDC issuer URL (e.g., https://gitlab.com)
#[arg(long)]
issuer: String,
/// Claims to match (format: key=value, can be specified multiple times)
#[arg(long = "claim", value_parser = parse_key_val::<String, String>)]
claims: Vec<(String, String)>,
},
/// List all service accounts for a project
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
/// Show service account details
#[command(visible_alias = "s")]
#[command(visible_alias = "get")]
Show {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Service account ID
id: String,
},
/// Delete a service account
#[command(visible_alias = "del")]
#[command(visible_alias = "rm")]
Delete {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Service account ID
id: String,
},
}
#[derive(Subcommand, Debug)]
enum EnvCommands {
/// Set an environment variable for a project
#[command(visible_alias = "s")]
Set {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Variable name (e.g., DATABASE_URL)
key: String,
/// Variable value
value: String,
/// Mark as secret (encrypted at rest)
#[arg(long)]
secret: bool,
/// Mark secret as protected (cannot be decrypted via API). Only applies to secrets. Defaults to true for secrets, must be false for non-secrets.
#[arg(long)]
protected: Option<bool>,
},
/// List environment variables for a project
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
/// Get the value of a specific environment variable
#[command(visible_alias = "g")]
Get {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Variable name
key: String,
},
/// Delete an environment variable from a project
#[command(visible_alias = "unset")]
#[command(visible_alias = "rm")]
#[command(visible_alias = "del")]
Delete {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Variable name
key: String,
},
/// Import environment variables from a file
#[command(visible_alias = "i")]
Import {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Path to file containing environment variables
/// Format: KEY=value or KEY=secret:value (for secrets)
/// Lines starting with # are comments
file: std::path::PathBuf,
},
/// Show environment variables for a deployment (read-only)
ShowDeployment {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Deployment ID
deployment_id: String,
},
}
#[derive(Subcommand, Debug)]
enum DomainCommands {
/// Add a custom domain to a project
#[command(visible_alias = "a")]
Add {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Domain name (e.g., example.com)
domain: String,
},
/// List custom domains for a project
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
/// Remove a custom domain from a project
#[command(visible_alias = "rm")]
#[command(visible_alias = "del")]
Remove {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Domain name
domain: String,
},
}
#[derive(Subcommand, Debug)]
enum ExtensionCommands {
/// Create or update an extension for a project
#[command(visible_alias = "c")]
#[command(visible_alias = "new")]
Create {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Extension name
extension: String,
/// Extension type (handler identifier, e.g., "aws-rds-provisioner", "oauth")
#[arg(long)]
r#type: String,
/// Extension spec as JSON string
#[arg(long)]
spec: String,
},
/// Update an extension (full replace)
#[command(visible_alias = "u")]
Update {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Extension name
extension: String,
/// Extension spec as JSON string
#[arg(long)]
spec: String,
},
/// Patch an extension (partial update, null values unset fields)
#[command(visible_alias = "p")]
Patch {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Extension name
extension: String,
/// Extension spec patch as JSON string
#[arg(long)]
spec: String,
},
/// List all extensions for a project
#[command(visible_alias = "ls")]
#[command(visible_alias = "l")]
List {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
},
/// Show extension details
#[command(visible_alias = "s")]
Show {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Extension name
extension: String,
},
/// Delete an extension from a project
#[command(visible_alias = "rm")]
#[command(visible_alias = "del")]
Delete {
/// Project name (optional if rise.toml contains [project] section)
#[arg(long, short = 'p')]
project: Option<String>,
/// Path to rise.toml (defaults to current directory)
#[arg(long, default_value = ".")]
path: String,
/// Extension name
extension: String,
},
}
/// Parse a single key-value pair
fn parse_key_val<T, U>(
s: &str,
) -> Result<(T, U), Box<dyn std::error::Error + Send + Sync + 'static>>
where
T: std::str::FromStr,
T::Err: std::error::Error + Send + Sync + 'static,
U: std::str::FromStr,
U::Err: std::error::Error + Send + Sync + 'static,
{
let pos = s
.find('=')
.ok_or_else(|| format!("invalid KEY=value: no `=` found in `{s}`"))?;
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
}
#[tokio::main]
async fn main() -> Result<()> {
// Initialize tracing for all commands
tracing_subscriber::registry()
.with(tracing_subscriber::EnvFilter::new(
std::env::var("RUST_LOG").unwrap_or_else(|_| "info".into()),
))
.with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
.init();
let cli = Cli::parse();
// Transform Deploy command to Deployment::Create for zero-duplication aliasing
let cli_command = match cli.command {
Commands::Deploy { args } => Commands::Deployment(DeploymentCommands::Create { args }),
other => other,
};
// Backend commands don't need CLI config (they use Settings from TOML/env vars)
// Only client commands (login, project, team, deployment, service-account) need it
if let Commands::Backend(backend_cmd) = &cli_command {
return backend::handle_backend_command(backend_cmd.clone()).await;
}
// Load CLI config for client commands
let http_client = Client::new();
let mut config = config::Config::load()?;
let backend_url = config.get_backend_url();
// Check version compatibility for all commands except Backend and Login
// (Backend commands don't use the HTTP API, Login might use a custom URL)
if !matches!(&cli_command, Commands::Backend(_) | Commands::Login { .. }) {
// Non-fatal version check - just warns user
let _ = version::check_version_compatibility(&http_client, &backend_url).await;
}
match &cli_command {
Commands::Login {
url,
browser: _,
device,
} => {
// Use provided URL or fall back to config default
let login_url = url.as_deref().unwrap_or(&backend_url);
if *device {
// Device flow (explicit)
login::handle_device_flow(&http_client, login_url, &mut config, url.as_deref())
.await?;
} else {
// Authorization code flow with PKCE (default)
login::handle_authorization_code_flow(
&http_client,
login_url,
&mut config,
url.as_deref(),
)
.await?;
}
}
Commands::Backend(_) => {
// Already handled above before config loading
unreachable!("Backend commands should have been handled earlier")
}
Commands::Encrypt { plaintext } => {
cli::encrypt::encrypt_command(&config, plaintext.clone()).await?;
}
Commands::Project(project_cmd) => match project_cmd {
ProjectCommands::Create {
name,
access_class,
owner,
path,
mode,
} => {
project::create_project(
&http_client,
&backend_url,
&config,
name,
access_class,
owner.clone(),
path,
mode,
)
.await?;
}
ProjectCommands::List {} => {
project::list_projects(&http_client, &backend_url, &config).await?;
}
ProjectCommands::Show { project } => {
project::show_project(&http_client, &backend_url, &config, project).await?;
}
ProjectCommands::Update {
project,
name,
access_class,
owner,
sync,
path,
} => {
project::update_project(
&http_client,
&backend_url,
&config,
project,
name.clone(),
access_class.clone(),
owner.clone(),
*sync,
path,
)
.await?;
}
ProjectCommands::Delete { project } => {
project::delete_project(&http_client, &backend_url, &config, project).await?;
}
ProjectCommands::AppUser(app_user_cmd) => {
let token = config.get_token().ok_or_else(|| {
anyhow::anyhow!("Not authenticated. Please run 'rise login' first")
})?;
match app_user_cmd {
AppUserCommands::Add {
project,
identifier,
path,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
cli::project::add_app_user(
&http_client,
&backend_url,
&token,
&project_name,
identifier,
)
.await?;
}
AppUserCommands::Remove {
project,
identifier,
path,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
cli::project::remove_app_user(
&http_client,
&backend_url,
&token,
&project_name,
identifier,
)
.await?;
}
AppUserCommands::List { project, path } => {
let project_name = resolve_project_name(project.clone(), path)?;
cli::project::list_app_users(
&http_client,
&backend_url,
&token,
&project_name,
)
.await?;
}
}
}
},
Commands::Team(team_cmd) => match team_cmd {
TeamCommands::Create {
name,
owners,
members,
} => {
let owners_vec: Option<Vec<String>> = owners.as_ref().map(|o| {
o.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
});
let members_vec: Vec<String> = members
.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect();
team::create_team(
&http_client,
&backend_url,
&config,
name,
owners_vec,
members_vec,
)
.await?;
}
TeamCommands::List {} => {
team::list_teams(&http_client, &backend_url, &config).await?;
}
TeamCommands::Show { team } => {
team::show_team(&http_client, &backend_url, &config, team).await?;
}
TeamCommands::Update {
team,
name,
add_owners,
remove_owners,
add_members,
remove_members,
} => {
let add_owners_vec: Vec<String> = add_owners
.as_ref()
.map(|s| {
s.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
})
.unwrap_or_default();
let remove_owners_vec: Vec<String> = remove_owners
.as_ref()
.map(|s| {
s.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
})
.unwrap_or_default();
let add_members_vec: Vec<String> = add_members
.as_ref()
.map(|s| {
s.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
})
.unwrap_or_default();
let remove_members_vec: Vec<String> = remove_members
.as_ref()
.map(|s| {
s.split(',')
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
.collect()
})
.unwrap_or_default();
team::update_team(
&http_client,
&backend_url,
&config,
team,
name.clone(),
add_owners_vec,
remove_owners_vec,
add_members_vec,
remove_members_vec,
)
.await?;
}
TeamCommands::Delete { team } => {
team::delete_team(&http_client, &backend_url, &config, team).await?;
}
},
Commands::Deployment(deployment_cmd) => match deployment_cmd {
DeploymentCommands::Create { args } => {
let project_name = resolve_project_name(args.project.clone(), &args.path)?;
// Both --image and --from cannot be specified together
if args.image.is_some() && args.from.is_some() {
eprintln!("Error: Cannot specify both --image and --from");
std::process::exit(1);
}
// For pre-built images, --http-port is required since we can't infer it
if let Some(image) = &args.image {
if args.http_port.is_none() {
eprintln!("Error: --http-port is required when using --image");
eprintln!(
"Example: rise deployment create {} --image {} --http-port 80",
project_name, image
);
std::process::exit(1);
}
}
// Pass through the http_port option - server will resolve from:
// 1. Explicit http_port (if provided)
// 2. Source deployment's http_port (if --from is used)
// 3. Project's PORT env var (if set)
// 4. Default 8080
deployment::create_deployment(
&http_client,
&backend_url,
&config,
deployment::DeploymentOptions {
project_name: &project_name,
path: &args.path,
image: args.image.as_deref(),
group: args.group.as_deref(),
expires_in: args.expire.as_deref(),
http_port: args.http_port,
build_args: &args.build_args,
from_deployment: args.from.as_deref(),
use_source_env_vars: args.use_source_env_vars,
},
)
.await?;
}
DeploymentCommands::List {
project,
path,
group,
limit,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
deployment::list_deployments(
&http_client,
&backend_url,
&config,
&project_name,
group.as_deref(),
*limit,
)
.await?;
}
DeploymentCommands::Show {
project,
path,
deployment_id,
follow,
timeout,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
deployment::show_deployment(
&http_client,
&backend_url,
&config,
&project_name,
deployment_id,
*follow,
timeout,
)
.await?;
}
DeploymentCommands::Stop {
project,
path,
group,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
deployment::stop_deployments_by_group(
&http_client,
&backend_url,
&config,
&project_name,
group,
)
.await?;
}
DeploymentCommands::Logs {
project,
path,
deployment_id,
follow,
tail,
timestamps,
since,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
let token = config.get_token().ok_or_else(|| {
anyhow::anyhow!("Not logged in. Please run 'rise login' first.")
})?;
deployment::get_logs(
&http_client,
&backend_url,
&token,
deployment::GetLogsParams {
project: &project_name,
deployment_id,
follow: *follow,
tail: *tail,
timestamps: *timestamps,
since: since.as_deref(),
},
)
.await?;
}
},
Commands::ServiceAccount(sa_cmd) => match sa_cmd {
ServiceAccountCommands::Create {
project,
path,
issuer,
claims,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
let claims_map: std::collections::HashMap<String, String> =
claims.iter().cloned().collect();
// Validate aud claim requirement
if !claims_map.contains_key("aud") {
eprintln!(
"Error: The 'aud' (audience) claim is required for service accounts."
);
eprintln!(" Recommended format: rise-project-{{project-name}}");
eprintln!(" Example: --claim aud=rise-project-{}", project_name);
std::process::exit(1);
}
// Validate at least one additional claim
if claims_map.len() < 2 {
eprintln!("Error: At least one claim in addition to 'aud' is required.");
eprintln!(" Example: --claim aud=... --claim project_path=myorg/myrepo");
std::process::exit(1);
}
service_account::create_service_account(
&http_client,
&backend_url,
&config,
&project_name,
issuer,
claims_map,
)
.await?;
}
ServiceAccountCommands::List { project, path } => {
let project_name = resolve_project_name(project.clone(), path)?;
service_account::list_service_accounts(
&http_client,
&backend_url,
&config,
&project_name,
)
.await?;
}
ServiceAccountCommands::Show { project, path, id } => {
let project_name = resolve_project_name(project.clone(), path)?;
service_account::show_service_account(
&http_client,
&backend_url,
&config,
&project_name,
id,
)
.await?;
}
ServiceAccountCommands::Delete { project, path, id } => {
let project_name = resolve_project_name(project.clone(), path)?;
service_account::delete_service_account(
&http_client,
&backend_url,
&config,
&project_name,
id,
)
.await?;
}
},
Commands::Env(env_cmd) => {
let token = config.get_token().ok_or_else(|| {
anyhow::anyhow!("Not authenticated. Please run 'rise login' first")
})?;
match env_cmd {
EnvCommands::Set {
project,
path,
key,
value,
secret,
protected,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
// Protected defaults to true for secrets, false for non-secrets
// Can be explicitly overridden with --protected flag
let is_protected = protected.unwrap_or(*secret);
env::set_env(
&http_client,
&backend_url,
&token,
&project_name,
key,
value,
*secret,
is_protected,
)
.await?;
}
EnvCommands::List { project, path } => {
let project_name = resolve_project_name(project.clone(), path)?;
env::list_env(&http_client, &backend_url, &token, &project_name).await?;
}
EnvCommands::Get { project, path, key } => {
let project_name = resolve_project_name(project.clone(), path)?;
env::get_env(&http_client, &backend_url, &token, &project_name, key).await?;
}
EnvCommands::Delete { project, path, key } => {
let project_name = resolve_project_name(project.clone(), path)?;
env::unset_env(&http_client, &backend_url, &token, &project_name, key).await?;
}
EnvCommands::Import {
project,
path,
file,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
env::import_env(&http_client, &backend_url, &token, &project_name, file)
.await?;
}
EnvCommands::ShowDeployment {
project,
path,
deployment_id,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
env::list_deployment_env(
&http_client,
&backend_url,
&token,
&project_name,
deployment_id,
)
.await?;
}
}
}
Commands::Domain(domain_cmd) => {
let token = config.get_token().ok_or_else(|| {
anyhow::anyhow!("Not authenticated. Please run 'rise login' first")
})?;
match domain_cmd {
DomainCommands::Add {
project,
path,
domain,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
domain::add_domain(
&http_client,
&backend_url,
&token,
&project_name,
domain,
Some(path),
)
.await?;
}
DomainCommands::List { project, path } => {
let project_name = resolve_project_name(project.clone(), path)?;
domain::list_domains(&http_client, &backend_url, &token, &project_name).await?;
}
DomainCommands::Remove {
project,
path,
domain,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
domain::remove_domain(
&http_client,
&backend_url,
&token,
&project_name,
domain,
Some(path),
)
.await?;
}
}
}
Commands::Extension(extension_cmd) => match extension_cmd {
ExtensionCommands::Create {
project,
path,
extension,
r#type,
spec,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
let spec: serde_json::Value =
serde_json::from_str(spec).context("Failed to parse spec as JSON")?;
extension::create_extension(&project_name, extension, r#type, spec).await?;
}
ExtensionCommands::Update {
project,
path,
extension,
spec,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
let spec: serde_json::Value =
serde_json::from_str(spec).context("Failed to parse spec as JSON")?;
extension::update_extension(&project_name, extension, spec).await?;
}
ExtensionCommands::Patch {
project,
path,
extension,
spec,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
let spec: serde_json::Value =
serde_json::from_str(spec).context("Failed to parse spec as JSON")?;
extension::patch_extension(&project_name, extension, spec).await?;
}
ExtensionCommands::List { project, path } => {
let project_name = resolve_project_name(project.clone(), path)?;
extension::list_extensions(&project_name).await?;
}
ExtensionCommands::Show {
project,
path,
extension,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
extension::show_extension(&project_name, extension).await?;
}
ExtensionCommands::Delete {
project,
path,
extension,
} => {
let project_name = resolve_project_name(project.clone(), path)?;
extension::delete_extension(&project_name, extension).await?;
}
},
Commands::Build {
tag,
path,
push,
build_args,
} => {
let options = build::BuildOptions::from_build_args(
&config,
tag.clone(),
path.clone(),
build_args,
)
.with_push(*push);
build::build_image(options)?;
}
Commands::Run {
project,
use_project_env,
path,
http_port,
expose,
run_env,
build_args,
} => {
let expose_port = expose.unwrap_or(*http_port);
cli::run::run_locally(
&http_client,
&config,
cli::run::RunOptions {
project_name: project.as_deref(),
use_project_env: *use_project_env,
path,
http_port: *http_port,
expose: expose_port,
run_env,
build_args,
},
)
.await?;
}
Commands::Deploy { .. } => {
// Already transformed to Deployment(Create) above
unreachable!("Deploy command should have been transformed to Deployment(Create)")
}
}
Ok(())
}