Skip to content

Commit 07453f2

Browse files
authored
fix(cli): allow multiple provider profiles to be deleted (#3032)
Signed-off-by: Gordon Sim <gsim@redhat.com>
1 parent 11dd373 commit 07453f2

4 files changed

Lines changed: 58 additions & 26 deletions

File tree

‎.agents/skills/openshell-cli/cli-reference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ Delete one or more providers by name.
593593
- `openshell provider profile import (--file <path>|--from <dir>)`
594594
- `openshell provider profile update <id> --file <path>`
595595
- `openshell provider profile lint (--file <path>|--from <dir>)`
596-
- `openshell provider profile delete <id>`
596+
- `openshell provider profile delete <id>...`
597597

598598
### Provider credential refresh
599599

‎crates/openshell-cli/src/main.rs‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,9 @@ enum ProviderProfileCommands {
10921092
/// Delete a custom provider profile.
10931093
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
10941094
Delete {
1095-
/// Provider profile id.
1096-
id: String,
1095+
/// Provider profile id(s).
1096+
#[arg(required = true, num_args = 1.., value_name = "ID")]
1097+
ids: Vec<String>,
10971098

10981099
/// Target platform-scoped profile (ignores --workspace).
10991100
#[arg(long)]
@@ -3626,10 +3627,10 @@ async fn run_async() -> Result<()> {
36263627
)
36273628
.await?;
36283629
}
3629-
ProviderProfileCommands::Delete { id, global } => {
3630+
ProviderProfileCommands::Delete { ids, global } => {
36303631
run::provider_profile_delete(
36313632
endpoint,
3632-
&id,
3633+
&ids,
36333634
profile_workspace(global),
36343635
&tls,
36353636
)
@@ -4577,17 +4578,23 @@ mod tests {
45774578
}) if id == "custom-api"
45784579
));
45794580

4580-
let delete =
4581-
Cli::try_parse_from(["openshell", "provider", "profile", "delete", "custom-api"])
4582-
.expect("provider profile delete should parse");
4581+
let delete = Cli::try_parse_from([
4582+
"openshell",
4583+
"provider",
4584+
"profile",
4585+
"delete",
4586+
"custom-api",
4587+
"custom-alt",
4588+
])
4589+
.expect("provider profile delete should parse");
45834590
assert!(matches!(
45844591
delete.command,
45854592
Some(Commands::Provider {
45864593
command: Some(ProviderCommands::Profile(ProviderProfileCommands::Delete {
4587-
id,
4594+
ids,
45884595
..
45894596
}))
4590-
}) if id == "custom-api"
4597+
}) if ids == vec!["custom-api".to_string(), "custom-alt".to_string()]
45914598
));
45924599
}
45934600

‎crates/openshell-cli/src/run.rs‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,23 +4418,25 @@ pub async fn provider_profile_lint(
44184418

44194419
pub async fn provider_profile_delete(
44204420
server: &str,
4421-
id: &str,
4421+
ids: &[String],
44224422
workspace: &str,
44234423
tls: &TlsOptions,
44244424
) -> Result<()> {
44254425
let mut client = grpc_client(server, tls).await?;
4426-
let response = client
4427-
.delete_provider_profile(DeleteProviderProfileRequest {
4428-
id: id.to_string(),
4429-
workspace: workspace.to_string(),
4430-
})
4431-
.await
4432-
.into_diagnostic()?
4433-
.into_inner();
4434-
if response.deleted {
4435-
println!("Deleted provider profile '{id}'.");
4436-
} else {
4437-
println!("Provider profile '{id}' was not deleted.");
4426+
for id in ids {
4427+
let response = client
4428+
.delete_provider_profile(DeleteProviderProfileRequest {
4429+
id: id.clone(),
4430+
workspace: workspace.to_string(),
4431+
})
4432+
.await
4433+
.into_diagnostic()?
4434+
.into_inner();
4435+
if response.deleted {
4436+
println!("{} Deleted provider profile {id}", "✓".green().bold());
4437+
} else {
4438+
println!("{} Provider profile {id} not found", "!".yellow());
4439+
}
44384440
}
44394441
Ok(())
44404442
}

‎crates/openshell-cli/tests/provider_commands_integration.rs‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,21 @@ binaries: [/usr/bin/custom]
19091909
.expect("custom provider should be stored");
19101910
assert_eq!(provider.r#type, "custom-api");
19111911

1912+
let mut custom_alt_profile = ts
1913+
.state
1914+
.profiles
1915+
.lock()
1916+
.await
1917+
.get("custom-api")
1918+
.cloned()
1919+
.expect("custom-api profile should be stored");
1920+
custom_alt_profile.id = "custom-alt".to_string();
1921+
ts.state
1922+
.profiles
1923+
.lock()
1924+
.await
1925+
.insert("custom-alt".to_string(), custom_alt_profile);
1926+
19121927
run::provider_delete(
19131928
&ts.endpoint,
19141929
&["custom-provider".to_string()],
@@ -1917,9 +1932,17 @@ binaries: [/usr/bin/custom]
19171932
)
19181933
.await
19191934
.expect("custom provider delete");
1920-
run::provider_profile_delete(&ts.endpoint, "custom-api", "default", &ts.tls)
1921-
.await
1922-
.expect("profile delete");
1935+
run::provider_profile_delete(
1936+
&ts.endpoint,
1937+
&["custom-api".to_string(), "custom-alt".to_string()],
1938+
"default",
1939+
&ts.tls,
1940+
)
1941+
.await
1942+
.expect("profile delete");
1943+
let profiles = ts.state.profiles.lock().await;
1944+
assert!(!profiles.contains_key("custom-api"));
1945+
assert!(!profiles.contains_key("custom-alt"));
19231946
}
19241947

19251948
#[tokio::test]

0 commit comments

Comments
 (0)