Skip to content

Commit

Permalink
feat(cli): Allow sorting in "app list" command
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed Aug 20, 2024
1 parent 017a104 commit fbaa1b4
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/cli/src/commands/app/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::pin::Pin;

use futures::{Stream, StreamExt};
use wasmer_api::types::DeployApp;
use wasmer_api::types::{DeployApp, DeployAppsSortBy};

use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ListFormatOpts};

Expand Down Expand Up @@ -34,6 +34,19 @@ pub struct CmdAppList {
/// Asks whether to display the next page or not
#[clap(long, default_value = "false")]
paging_mode: bool,

/// Sort order for apps.
///
/// Use: --newest, --oldest or --last-updated
#[clap(long, default_value = "last-updated")]
sort: AppSort,
}

#[derive(clap::ValueEnum, Clone, Copy, Debug)]
pub enum AppSort {
Newest,
Oldest,
LastUpdated,
}

#[async_trait::async_trait]
Expand All @@ -43,14 +56,20 @@ impl AsyncCliCommand for CmdAppList {
async fn run_async(self) -> Result<(), anyhow::Error> {
let client = self.env.client()?;

let sort = match self.sort {
AppSort::Newest => DeployAppsSortBy::Newest,
AppSort::Oldest => DeployAppsSortBy::Oldest,
AppSort::LastUpdated => DeployAppsSortBy::MostActive,
};

let apps_stream: Pin<
Box<dyn Stream<Item = Result<Vec<DeployApp>, anyhow::Error>> + Send + Sync>,
> = if let Some(ns) = self.namespace.clone() {
Box::pin(wasmer_api::query::namespace_apps(&client, ns).await)
Box::pin(wasmer_api::query::namespace_apps(&client, ns, sort).await)
} else if self.all {
Box::pin(wasmer_api::query::user_accessible_apps(&client).await?)
Box::pin(wasmer_api::query::user_accessible_apps(&client, sort).await?)
} else {
Box::pin(wasmer_api::query::user_apps(&client).await)
Box::pin(wasmer_api::query::user_apps(&client, sort).await)
};

let mut apps_stream = std::pin::pin!(apps_stream);
Expand Down

0 comments on commit fbaa1b4

Please sign in to comment.