Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add integrations list command #267

Merged
merged 6 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 = "integrations" }
#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::Integration;
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<Integration> for IntegrationRow {
fn from(integration: Integration) -> 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