Skip to content

Commit

Permalink
add integrations list command (#267)
Browse files Browse the repository at this point in the history
* add `integrations list` command

* update changelog

* `Integration` -> `IntegrationSummary`

* update lockfile

* update fiberplane
  • Loading branch information
mellowagain authored Jan 12, 2024
1 parent 49ecb1c commit 20e8a66
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format of this file is based on [Keep a Changelog](https://keepachangelog.co

## [Unreleased]

- Add `integrations list` command (#267)

## [2.17.0]

- Fixed an issue with CLI argument completion failing. (#264)
Expand Down
53 changes: 30 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
100 changes: 100 additions & 0 deletions src/integrations.rs
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(),
}
}
}
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod data_sources;
mod events;
mod experiments;
mod fp_urls;
mod integrations;
mod interactive;
mod labels;
mod manifest;
Expand Down Expand Up @@ -119,11 +120,9 @@ enum SubCommand {
Experiments(experiments::Arguments),

/// Login to Fiberplane and authorize the CLI to access your account
#[clap()]
Login,

/// Logout from Fiberplane
#[clap()]
Logout,

/// Interact with labels
Expand Down Expand Up @@ -175,10 +174,12 @@ enum SubCommand {
Shell(shell::Arguments),

/// Snippets allow you to save reusable groups of cells and insert them into notebooks.
#[clap(alias = "snippet")]
Snippets(snippets::Arguments),

/// Views allow you to save label searches and display them as a view, allowing you to search for
/// notebooks easier and more convenient
#[clap(alias = "view")]
Views(views::Arguments),

/// Interact with triggers
Expand All @@ -195,10 +196,10 @@ enum SubCommand {
Events(events::Arguments),

/// Interact with API tokens
#[clap(alias = "token")]
Tokens(tokens::Arguments),

/// Update the current FP binary
#[clap()]
Update(update::Arguments),

/// Interact with user details
Expand All @@ -217,15 +218,20 @@ enum SubCommand {
#[clap(aliases = &["webhook", "wh"])]
Webhooks(webhooks::Arguments),

/// Interact with integrations
///
/// Integrations allow you to integrate various third-party tools into Fiberplane
#[clap(alias = "integration")]
Integrations(integrations::Arguments),

/// Display extra version information
#[clap()]
Version(version::Arguments),

/// Generate fp shell completions for your shell and print to stdout
#[clap(hide = true)]
Completions {
#[clap(value_enum)]
shell: clap_complete::Shell,
shell: Shell,
},

/// Generate markdown reference for fp.
Expand Down Expand Up @@ -313,6 +319,7 @@ async fn main() {
Users(args) => users::handle_command(args).await,
Workspaces(args) => workspaces::handle_command(args).await,
Webhooks(args) => webhooks::handle_command(args).await,
Integrations(args) => integrations::handle_command(args).await,
Version(args) => version::handle_command(args).await,
Completions { shell } => {
let output = generate_completions(shell);
Expand Down

0 comments on commit 20e8a66

Please sign in to comment.