-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
integrations list
command (#267)
* add `integrations list` command * update changelog * `Integration` -> `IntegrationSummary` * update lockfile * update fiberplane
- Loading branch information
1 parent
49ecb1c
commit 20e8a66
Showing
5 changed files
with
145 additions
and
29 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,6 @@ vergen = { version = "8.0.0", features = [ | |
] } | ||
|
||
[patch.crates-io] | ||
# fiberplane = { git = "ssh://[email protected]/fiberplane/fiberplane.git", branch = "main" } | ||
fiberplane = { git = "ssh://[email protected]/fiberplane/fiberplane.git", branch = "main" } | ||
#fp-bindgen-support = { git = "ssh://[email protected]/fiberplane/fp-bindgen.git", branch = "release-3.0.0" } | ||
#fp-bindgen-macros = { git = "ssh://[email protected]/fiberplane/fp-bindgen.git", branch = "release-3.0.0" } |
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,100 @@ | ||
use crate::config::api_client_configuration; | ||
use crate::output::{output_json, output_list}; | ||
use anyhow::Result; | ||
use clap::{Parser, ValueEnum}; | ||
use cli_table::Table; | ||
use fiberplane::api_client::integrations_get; | ||
use fiberplane::models::integrations::IntegrationSummary; | ||
use std::path::PathBuf; | ||
use time::format_description::well_known::Rfc3339; | ||
use url::Url; | ||
|
||
#[derive(Parser)] | ||
pub struct Arguments { | ||
#[clap(subcommand)] | ||
sub_command: SubCommand, | ||
} | ||
|
||
#[derive(Parser)] | ||
enum SubCommand { | ||
/// List all integrations | ||
List(ListArgs), | ||
} | ||
|
||
pub async fn handle_command(args: Arguments) -> Result<()> { | ||
match args.sub_command { | ||
SubCommand::List(args) => handle_integrations_list(args).await, | ||
} | ||
} | ||
|
||
#[derive(Parser)] | ||
struct ListArgs { | ||
/// Page to display | ||
#[clap(long)] | ||
page: Option<i32>, | ||
|
||
/// Amount of integrations to display per page | ||
#[clap(long)] | ||
limit: Option<i32>, | ||
|
||
/// Output of the webhooks | ||
#[clap(long, short, default_value = "table", value_enum)] | ||
output: IntegrationOutput, | ||
|
||
#[clap(from_global)] | ||
base_url: Url, | ||
|
||
#[clap(from_global)] | ||
config: Option<PathBuf>, | ||
|
||
#[clap(from_global)] | ||
token: Option<String>, | ||
} | ||
|
||
#[derive(ValueEnum, Clone)] | ||
enum IntegrationOutput { | ||
/// Output the details of the integrations as a table | ||
Table, | ||
|
||
/// Output the integration as JSON | ||
Json, | ||
} | ||
|
||
async fn handle_integrations_list(args: ListArgs) -> Result<()> { | ||
let client = api_client_configuration(args.token, args.config, args.base_url).await?; | ||
let integrations = integrations_get(&client, args.page, args.limit).await?; | ||
|
||
match args.output { | ||
IntegrationOutput::Table => { | ||
let rows: Vec<IntegrationRow> = integrations.into_iter().map(Into::into).collect(); | ||
output_list(rows) | ||
} | ||
IntegrationOutput::Json => output_json(&integrations), | ||
} | ||
} | ||
|
||
#[derive(Table)] | ||
struct IntegrationRow { | ||
#[table(title = "ID")] | ||
id: String, | ||
|
||
#[table(title = "Status")] | ||
status: String, | ||
|
||
#[table(title = "Created at")] | ||
created_at: String, | ||
|
||
#[table(title = "Updated at")] | ||
updated_at: String, | ||
} | ||
|
||
impl From<IntegrationSummary> for IntegrationRow { | ||
fn from(integration: IntegrationSummary) -> Self { | ||
Self { | ||
id: integration.id.to_string(), | ||
status: integration.status.to_string(), | ||
created_at: integration.created_at.format(&Rfc3339).unwrap_or_default(), | ||
updated_at: integration.updated_at.format(&Rfc3339).unwrap_or_default(), | ||
} | ||
} | ||
} |
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