use clap::Args;
use eyre::{OptionExt, WrapErr};
use tracing::info;
use openstack_cli_core::cli::CliArgs;
use openstack_cli_core::error::OpenStackCliError;
use openstack_cli_core::output::OutputProcessor;
use openstack_sdk::AsyncOpenStack;
use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::image::v2::image::location::list;
use openstack_types::image::v2::image::location::response;
#[derive(Args)]
#[command(about = "Get Location")]
pub struct LocationsCommand {
#[command(flatten)]
query: QueryParameters,
#[command(flatten)]
path: PathParameters,
}
#[derive(Args)]
struct QueryParameters {}
#[derive(Args)]
struct PathParameters {
#[arg(
help_heading = "Path parameters",
id = "path_param_image_id",
value_name = "IMAGE_ID"
)]
image_id: String,
}
impl LocationsCommand {
pub async fn take_action<C: CliArgs>(
&self,
parsed_args: &C,
client: &mut AsyncOpenStack,
) -> Result<(), OpenStackCliError> {
info!("List Locations");
let op =
OutputProcessor::from_args(parsed_args, Some("image.image/location"), Some("list"));
op.validate_args(parsed_args)?;
let mut ep_builder = list::Request::builder();
ep_builder.image_id(&self.path.image_id);
let ep = ep_builder
.build()
.map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
let data: serde_json::Value = ep.query_async(client).await?;
op.output_single::<response::list::LocationResponse>(data.clone())?;
op.show_command_hint()?;
Ok(())
}
}