systemprompt_cli/commands/cloud/
mod.rs1pub mod auth;
2pub mod db;
3mod deploy;
4pub mod dockerfile;
5mod domain;
6mod init;
7pub mod profile;
8mod restart;
9mod secrets;
10mod status;
11pub mod sync;
12pub mod templates;
13pub mod tenant;
14pub mod types;
15
16pub use systemprompt_cloud::{Environment, OAuthProvider};
17
18use crate::cli_settings::CliConfig;
19use crate::descriptor::{CommandDescriptor, DescribeCommand};
20use anyhow::Result;
21use clap::Subcommand;
22
23#[derive(Debug, Subcommand)]
24pub enum CloudCommands {
25 #[command(subcommand, about = "Authentication (login, logout, whoami)")]
26 Auth(auth::AuthCommands),
27
28 #[command(about = "Initialize project structure")]
29 Init {
30 #[arg(long)]
31 force: bool,
32 },
33
34 #[command(subcommand_required = false, about = "Manage tenants (local or cloud)")]
35 Tenant {
36 #[command(subcommand)]
37 command: Option<tenant::TenantCommands>,
38 },
39
40 #[command(subcommand_required = false, about = "Manage profiles")]
41 Profile {
42 #[command(subcommand)]
43 command: Option<profile::ProfileCommands>,
44 },
45
46 #[command(about = "Deploy to systemprompt.io Cloud")]
47 Deploy {
48 #[arg(long)]
49 skip_push: bool,
50
51 #[arg(long, short = 'p', help = "Profile name to deploy")]
52 profile: Option<String>,
53
54 #[arg(
55 long,
56 help = "Skip pre-deploy sync from cloud (WARNING: may lose runtime files)"
57 )]
58 no_sync: bool,
59
60 #[arg(short = 'y', long, help = "Skip confirmation prompts")]
61 yes: bool,
62
63 #[arg(long, help = "Preview sync without deploying")]
64 dry_run: bool,
65 },
66
67 #[command(about = "Check cloud deployment status")]
68 Status,
69
70 #[command(about = "Restart tenant machine")]
71 Restart {
72 #[arg(long)]
73 tenant: Option<String>,
74
75 #[arg(short = 'y', long, help = "Skip confirmation prompts")]
76 yes: bool,
77 },
78
79 #[command(
80 subcommand_required = false,
81 about = "Sync between local and cloud environments"
82 )]
83 Sync {
84 #[command(subcommand)]
85 command: Option<sync::SyncCommands>,
86 },
87
88 #[command(subcommand, about = "Manage secrets for cloud tenant")]
89 Secrets(secrets::SecretsCommands),
90
91 #[command(about = "Generate Dockerfile based on discovered extensions")]
92 Dockerfile,
93
94 #[command(subcommand, about = "Cloud database operations")]
95 Db(db::CloudDbCommands),
96
97 #[command(subcommand, about = "Manage custom domain and TLS certificates")]
98 Domain(domain::DomainCommands),
99}
100
101impl DescribeCommand for CloudCommands {
102 fn descriptor(&self) -> CommandDescriptor {
103 match self {
104 Self::Deploy { .. } => CommandDescriptor::PROFILE_AND_SECRETS,
105 Self::Sync { command: Some(_) } | Self::Secrets { .. } => {
106 CommandDescriptor::PROFILE_AND_SECRETS
107 },
108 Self::Status | Self::Restart { .. } | Self::Domain { .. } => {
109 CommandDescriptor::PROFILE_ONLY
110 },
111 _ => CommandDescriptor::NONE,
112 }
113 }
114}
115
116impl CloudCommands {
117 pub const fn requires_profile(&self) -> bool {
118 matches!(
119 self,
120 Self::Sync { command: Some(_) }
121 | Self::Status
122 | Self::Restart { .. }
123 | Self::Secrets { .. }
124 | Self::Domain { .. }
125 )
126 }
127
128 pub const fn requires_secrets(&self) -> bool {
129 matches!(self, Self::Sync { command: Some(_) } | Self::Secrets { .. })
130 }
131}
132
133pub async fn execute(cmd: CloudCommands, config: &CliConfig) -> Result<()> {
134 match cmd {
135 CloudCommands::Auth(cmd) => auth::execute(cmd, config).await,
136 CloudCommands::Init { force } => init::execute(force, config),
137 CloudCommands::Tenant { command } => tenant::execute(command, config).await,
138 CloudCommands::Profile { command } => profile::execute(command, config).await,
139 CloudCommands::Deploy {
140 skip_push,
141 profile,
142 no_sync,
143 yes,
144 dry_run,
145 } => {
146 deploy::execute(
147 deploy::DeployArgs {
148 skip_push,
149 profile_name: profile,
150 no_sync,
151 yes,
152 dry_run,
153 },
154 config,
155 )
156 .await
157 },
158 CloudCommands::Status => {
159 let result = status::execute(config).await?;
160 crate::shared::render_result(&result);
161 Ok(())
162 },
163 CloudCommands::Restart { tenant, yes } => {
164 let result = restart::execute(tenant, yes, config).await?;
165 crate::shared::render_result(&result);
166 Ok(())
167 },
168 CloudCommands::Sync { command } => sync::execute(command, config).await,
169 CloudCommands::Secrets(cmd) => secrets::execute(cmd, config).await,
170 CloudCommands::Dockerfile => execute_dockerfile(config),
171 CloudCommands::Db(cmd) => db::execute(cmd, config).await,
172 CloudCommands::Domain(cmd) => domain::execute(cmd, config).await,
173 }
174}
175
176fn execute_dockerfile(config: &CliConfig) -> Result<()> {
177 use crate::shared::project::ProjectRoot;
178 use types::DockerfileOutput;
179
180 let project = ProjectRoot::discover().map_err(|e| anyhow::anyhow!("{}", e))?;
181 let content = dockerfile::generate_dockerfile_content(project.as_path());
182
183 let output = DockerfileOutput {
184 content: content.clone(),
185 };
186
187 if config.is_json_output() {
188 crate::shared::render_result(
189 &crate::shared::CommandResult::copy_paste(output).with_title("Dockerfile"),
190 );
191 } else {
192 systemprompt_logging::CliService::info(&content);
193 }
194
195 Ok(())
196}