Skip to content

Commit 7c3184c

Browse files
authored
Merge pull request #3173 from itowlson/prepare-to-remove-cloud
Warn if `spin deploy` rather than `spin cloud deploy`
2 parents 14d29d5 + 2c1b292 commit 7c3184c

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/commands/cloud.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clap::Args;
44

55
#[derive(Debug, Args, PartialEq)]
66
#[clap(
7-
about = "Package and upload an application to the Fermyon Cloud.",
7+
about = "Package and upload an application to a deployment environment.",
88
allow_hyphen_values = true,
99
disable_help_flag = true
1010
)]
@@ -16,7 +16,7 @@ pub struct DeployCommand {
1616

1717
#[derive(Debug, Args, PartialEq)]
1818
#[clap(
19-
about = "Log into the Fermyon Cloud.",
19+
about = "Log into a deployment environment.",
2020
allow_hyphen_values = true,
2121
disable_help_flag = true
2222
)]
@@ -26,18 +26,43 @@ pub struct LoginCommand {
2626
args: Vec<String>,
2727
}
2828

29+
/// Transitional for compatibility: this will be removed as part of vendor-neutrality work.
30+
const DEFAULT_DEPLOY_PLUGIN: &str = "cloud";
31+
32+
/// The environment variable for setting the plugin to be used for operations relating
33+
/// to remote hosts. This allows the `spin deploy` and `spin login` shortcuts instead of
34+
/// `spin whatever deploy` etc.
35+
const DEPLOY_PLUGIN_ENV: &str = "SPIN_DEPLOY_PLUGIN";
36+
2937
impl DeployCommand {
3038
pub async fn run(self, app: clap::App<'_>) -> Result<()> {
31-
let mut cmd = vec!["cloud".to_string(), "deploy".to_string()];
39+
const CMD: &str = "deploy";
40+
41+
let deploy_plugin = deployment_plugin(CMD)?;
42+
let mut cmd = vec![deploy_plugin, CMD.to_string()];
3243
cmd.append(&mut self.args.clone());
3344
execute_external_subcommand(cmd, app).await
3445
}
3546
}
3647

3748
impl LoginCommand {
3849
pub async fn run(self, app: clap::App<'_>) -> Result<()> {
39-
let mut cmd = vec!["cloud".to_string(), "login".to_string()];
50+
const CMD: &str = "login";
51+
52+
let deploy_plugin = deployment_plugin(CMD)?;
53+
let mut cmd = vec![deploy_plugin, CMD.to_string()];
4054
cmd.append(&mut self.args.clone());
4155
execute_external_subcommand(cmd, app).await
4256
}
4357
}
58+
59+
fn deployment_plugin(cmd: &str) -> anyhow::Result<String> {
60+
match std::env::var(DEPLOY_PLUGIN_ENV) {
61+
Ok(v) => Ok(v),
62+
Err(std::env::VarError::NotPresent) => {
63+
terminal::warn!("`spin {cmd}` will soon need to be told which deployment plugin to use.\nRun a plugin command (e.g. `spin {DEFAULT_DEPLOY_PLUGIN} {cmd}`), or set the `{DEPLOY_PLUGIN_ENV}` environment variable, instead.\nDefaulting to `{DEFAULT_DEPLOY_PLUGIN}` plugin.");
64+
Ok(DEFAULT_DEPLOY_PLUGIN.to_string())
65+
}
66+
Err(_) => anyhow::bail!("{DEPLOY_PLUGIN_ENV} was defined but its value could not be read"),
67+
}
68+
}

0 commit comments

Comments
 (0)