Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 136 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ tracing-appender = "0.2"
tracing-subscriber = { version = "0.3", features = ["json", "env-filter"] }
url = { version = "2", features = ["serde"] }
webbrowser = "1"
inquire = "0.9.4"

# The profile that 'dist' will build with
[profile.dist]
Expand Down
1 change: 1 addition & 0 deletions crates/tower-cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ schemars = "1.0"
toml = { workspace = true }
toml_edit = { workspace = true }
tracing-subscriber = { workspace = true }
inquire = { workspace = true }

[dev-dependencies]
tempfile = "3.12"
Expand Down
30 changes: 30 additions & 0 deletions crates/tower-cmd/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,17 @@ impl ResponseEntity for tower_api::apis::default_api::ListEnvironmentsSuccess {
}
}

impl ResponseEntity for tower_api::apis::default_api::DeleteEnvironmentSuccess {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is autogenerated, right? If not, I hate it :D

type Data = tower_api::models::DeleteEnvironmentResponse;

fn extract_data(self) -> Option<Self::Data> {
match self {
Self::Status200(resp) => Some(resp),
Self::UnknownValue(_) => None,
}
}
}

pub async fn list_environments(
config: &Config,
) -> Result<
Expand Down Expand Up @@ -1067,6 +1078,25 @@ pub async fn create_environment(
.await
}

pub async fn delete_environment(
config: &Config,
name: &str,
) -> Result<
tower_api::models::DeleteEnvironmentResponse,
Error<tower_api::apis::default_api::DeleteEnvironmentError>,
> {
let api_config = &config.into();

let params = tower_api::apis::default_api::DeleteEnvironmentParams {
name: name.to_string(),
};

unwrap_api_response(tower_api::apis::default_api::delete_environment(
api_config, params,
))
.await
}

pub async fn list_schedules(
config: &Config,
app_name: Option<&str>,
Expand Down
43 changes: 43 additions & 0 deletions crates/tower-cmd/src/environments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{value_parser, Arg, ArgMatches, Command};
use config::Config;
use inquire::Confirm;

use crate::{api, output};

Expand All @@ -8,6 +9,18 @@ pub fn environments_cmd() -> Command {
.about("Manage the environments in your current Tower account")
.arg_required_else_help(true)
.subcommand(Command::new("list").about("List all of your environments"))
.subcommand(
Command::new("delete")
.arg(
Arg::new("name")
.short('n')
.long("name")
.value_parser(value_parser!(String))
.required(true)
.action(clap::ArgAction::Set),
)
.about("Delete an environment"),
)
.subcommand(
Command::new("create")
.arg(
Expand Down Expand Up @@ -50,3 +63,33 @@ pub async fn do_create(config: Config, args: &ArgMatches) {

output::success(&format!("Environment '{}' created", name));
}

pub async fn do_delete(config: Config, args: &ArgMatches) {
let name = args.get_one::<String>("name").unwrap_or_else(|| {
output::die("Environment name (--name) is required");
});

let ans = Confirm::new(&format!(
"Are you sure you want to delete your {name} environment?"
))
.with_default(false)
.prompt();

match ans {
Ok(true) => {
output::with_spinner(
&format!("Deleting environment {name}"),
api::delete_environment(&config, name),
)
.await;

output::success(&format!("Environment '{name}' deleted"));
}
Ok(false) => output::write("Ok.\n"),
Err(_) => {
output::error(
"Something went wrong. Please try again, and contact us if the issue persists.",
);
}
}
}
1 change: 1 addition & 0 deletions crates/tower-cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl App {
Some(("create", args)) => {
environments::do_create(sessionized_config, args).await
}
Some(("delete", args)) => environments::do_delete(sessionized_config, args).await,
_ => {
environments::environments_cmd().print_help().unwrap();
}
Expand Down
Loading