-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kudoctl): get instances command
Signed-off-by: Nils Ponsard <[email protected]>
- Loading branch information
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
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,33 @@ | ||
use super::output::{self, OutputFormat}; | ||
use crate::{ | ||
client::{self, instance::GetInstancesResponse, request::Client}, | ||
config, | ||
}; | ||
use anyhow::{Context, Result}; | ||
use std::fmt::Display; | ||
|
||
/// get instances subcommand execution | ||
/// Does the request, then formats the output. | ||
pub async fn execute( | ||
conf: &config::Config, | ||
format: OutputFormat, | ||
show_header: bool, | ||
) -> Result<String> { | ||
let client = Client::new(conf).context("Error creating client")?; | ||
let mut result = client::instance::list(&client).await?; | ||
result.show_header = show_header; | ||
output::format_output(result, format) | ||
} | ||
|
||
impl Display for GetInstancesResponse { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
if self.show_header { | ||
writeln!(f, "ID\tSTATUS")?; | ||
} | ||
|
||
for inst in &self.instances { | ||
writeln!(f, "{}\t{}\n", inst.id, inst.status)?; | ||
} | ||
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
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