Skip to content

Commit

Permalink
Enable updating a link with 'spin cloud link sqlite'
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
  • Loading branch information
kate-goldenring committed Oct 5, 2023
1 parent 8bb8d74 commit 790ffad
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ impl SqliteLinkCommand {
let existing_link_for_other_database = other_dbs
.iter()
.find_map(|d| find_database_link(d, &self.label));
let success_msg = format!(
r#"Database "{}" is now linked to app "{}" with the label "{}""#,
self.database, self.app, self.label
);
match (existing_link_for_database, existing_link_for_other_database) {
(Some(link), _) => {
anyhow::bail!(
Expand All @@ -82,18 +86,34 @@ impl SqliteLinkCommand {
);
}
(_, Some(link)) => {
anyhow::bail!(
r#"Database "{}" is already linked to app "{}" with label "{}""#,
let prompt = format!(
r#"Database "{}" is already linked to app "{}" with label "{}". Link to database "{}" instead?"#,
link.resource,
link.app_name(),
link.resource_label.label,
self.database,
);
if dialoguer::Confirm::new()
.with_prompt(prompt)
.default(false)
.interact_opt()?
.unwrap_or_default()
{
CloudClient::remove_database_link(&client, &link.resource, link.resource_label)
.await?;
let resource_label = ResourceLabel {
app_id,
label: self.label,
app_name: None,
};
CloudClient::create_database_link(&client, &self.database, resource_label)
.await?;
println!("{success_msg}");
} else {
println!("The link has not been updated");
}
}
(None, None) => {
let success_msg = format!(
"Database '{}' is now linked to app '{}' with the label '{}'",
self.database, self.app, self.label
);
let resource_label = ResourceLabel {
app_id,
label: self.label,
Expand Down

0 comments on commit 790ffad

Please sign in to comment.