-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4960 from wasmerio/list-regions
Add `regions` subcommand to `app` subcommand
- Loading branch information
Showing
8 changed files
with
592 additions
and
344 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::{ | ||
commands::AsyncCliCommand, | ||
opts::{ApiOpts, ListFormatOpts, WasmerEnv}, | ||
}; | ||
use is_terminal::IsTerminal; | ||
|
||
/// List available Edge regions. | ||
#[derive(clap::Parser, Debug)] | ||
pub struct CmdAppRegionsList { | ||
/* --- Common flags --- */ | ||
#[clap(flatten)] | ||
#[allow(missing_docs)] | ||
pub api: ApiOpts, | ||
|
||
#[clap(flatten)] | ||
pub env: WasmerEnv, | ||
|
||
/// Don't print any message. | ||
#[clap(long)] | ||
pub quiet: bool, | ||
|
||
/// Do not prompt for user input. | ||
#[clap(long, default_value_t = !std::io::stdin().is_terminal())] | ||
pub non_interactive: bool, | ||
|
||
#[clap(flatten)] | ||
pub fmt: ListFormatOpts, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppRegionsList { | ||
type Output = (); | ||
|
||
async fn run_async(self) -> Result<Self::Output, anyhow::Error> { | ||
let client = self.api.client()?; | ||
let regions = wasmer_api::query::get_all_app_regions(&client).await?; | ||
|
||
println!("{}", self.fmt.format.render(regions.as_slice())); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::commands::AsyncCliCommand; | ||
|
||
pub mod list; | ||
mod utils; | ||
|
||
/// Informations about available Edge regioins. | ||
#[derive(Debug, clap::Parser)] | ||
pub enum CmdAppRegions { | ||
List(list::CmdAppRegionsList), | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl AsyncCliCommand for CmdAppRegions { | ||
type Output = (); | ||
|
||
async fn run_async(self) -> Result<Self::Output, anyhow::Error> { | ||
match self { | ||
Self::List(c) => { | ||
c.run_async().await?; | ||
Ok(()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod render; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::utils::render::CliRender; | ||
use comfy_table::{Cell, Table}; | ||
use wasmer_api::types::AppRegion; | ||
|
||
impl CliRender for AppRegion { | ||
fn render_item_table(&self) -> String { | ||
let mut table = Table::new(); | ||
let AppRegion { | ||
name, | ||
city, | ||
country, | ||
.. | ||
}: &AppRegion = self; | ||
|
||
table.load_preset(comfy_table::presets::NOTHING); | ||
table.set_content_arrangement(comfy_table::ContentArrangement::Dynamic); | ||
|
||
table.add_rows([ | ||
vec![ | ||
Cell::new("Name".to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
Cell::new("City".to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
Cell::new("Country code".to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
], | ||
vec![ | ||
Cell::new(name.to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
Cell::new(city.to_string()), | ||
Cell::new(country.to_string()), | ||
], | ||
]); | ||
table.to_string() | ||
} | ||
|
||
fn render_list_table(items: &[Self]) -> String { | ||
if items.is_empty() { | ||
return String::new(); | ||
} | ||
let mut table = Table::new(); | ||
table.load_preset(comfy_table::presets::NOTHING); | ||
//table.set_content_arrangement(comfy_table::ContentArrangement::Dynamic); | ||
|
||
table.set_header(vec![ | ||
Cell::new("Name".to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
Cell::new("City".to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
Cell::new("Country code".to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
]); | ||
table.add_rows(items.iter().map(|s| { | ||
vec![ | ||
Cell::new(s.name.to_string()).add_attribute(comfy_table::Attribute::Bold), | ||
Cell::new(s.city.to_string()), | ||
Cell::new(s.country.to_string()), | ||
] | ||
})); | ||
table.to_string() | ||
} | ||
} |