Skip to content

Commit

Permalink
feat(cli): Allow "wasmer app get" with an app version id
Browse files Browse the repository at this point in the history
Extends the `AppIdent` to support app version ids, so commands like "app
get/info/..." work with a specific app version.

This helps usability with usability and debugging.
  • Loading branch information
theduke committed May 14, 2024
1 parent b663584 commit 81550fa
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/cli/src/commands/app/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use crate::{
/// Can be either a namespace/name a plain name or an app id.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum AppIdent {
/// Backend app id like "da_xxysw34234"
AppId(String),
/// Backend app VERSION id like "dav_xxysw34234"
AppVersionId(String),
NamespacedName(String, String),
Alias(String),
}
Expand All @@ -30,6 +33,13 @@ impl AppIdent {
AppIdent::AppId(app_id) => wasmer_api::query::get_app_by_id(client, app_id.clone())
.await
.with_context(|| format!("Could not find app with id '{}'", app_id)),
AppIdent::AppVersionId(id) => {
let (app, _version) =
wasmer_api::query::get_app_version_by_id_with_app(client, id.clone())
.await
.with_context(|| format!("Could not query for app version id '{}'", id))?;
Ok(app)
}
AppIdent::Alias(name) => wasmer_api::query::get_app_by_alias(client, name.clone())
.await?
.with_context(|| format!("Could not find app with name '{name}'")),
Expand Down Expand Up @@ -59,13 +69,15 @@ impl std::str::FromStr for AppIdent {
name.to_string(),
))
} else if let Ok(id) = GlobalId::parse_prefixed(s) {
if id.kind() == NodeKind::DeployApp {
Ok(Self::AppId(s.to_string()))
} else {
bail!(
"invalid app identifier '{s}': expected an app id, but id is of type {kind}",
kind = id.kind(),
);
match id.kind() {
NodeKind::DeployApp => Ok(Self::AppId(s.to_string())),
NodeKind::DeployAppVersion => Ok(Self::AppVersionId(s.to_string())),
_ => {
bail!(
"invalid app identifier '{s}': expected an app id, but id is of type {kind}",
kind = id.kind(),
);
}
}
} else {
Ok(Self::Alias(s.to_string()))
Expand Down

0 comments on commit 81550fa

Please sign in to comment.