-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows us to experiment with cling's design and limitations in practice. There will be further improvements but this is a fully functional migration.
- Loading branch information
1 parent
7ee65de
commit 8e702cd
Showing
26 changed files
with
504 additions
and
904 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,45 +1,32 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use cling::prelude::*; | ||
use cronback_api_model::admin::APIKeyMetaData; | ||
|
||
use crate::args::CommonOptions; | ||
use crate::{emitln, Command}; | ||
|
||
#[derive(Clone, Debug, Parser)] | ||
#[derive(CliRunnable, CliParam, Clone, Debug, Parser)] | ||
#[cling(run = "create")] | ||
pub struct Create { | ||
/// The name of the key to be created | ||
name: String, | ||
} | ||
|
||
#[async_trait] | ||
impl Command for Create { | ||
async fn run< | ||
A: tokio::io::AsyncWrite + Send + Sync + Unpin, | ||
B: tokio::io::AsyncWrite + Send + Sync + Unpin, | ||
>( | ||
&self, | ||
out: &mut tokio::io::BufWriter<A>, | ||
_err: &mut tokio::io::BufWriter<B>, | ||
common_options: &CommonOptions, | ||
) -> Result<()> { | ||
let client = common_options.new_client()?; | ||
async fn create(common_options: &CommonOptions, opts: &Create) -> Result<()> { | ||
let client = common_options.new_client()?; | ||
|
||
let response = cronback_client::api_keys::gen( | ||
&client, | ||
&self.name, | ||
APIKeyMetaData::default(), | ||
) | ||
.await?; | ||
let response = cronback_client::api_keys::gen( | ||
&client, | ||
&opts.name, | ||
APIKeyMetaData::default(), | ||
) | ||
.await?; | ||
|
||
let response = response.into_inner()?; | ||
let response = response.into_inner()?; | ||
|
||
emitln!( | ||
out, | ||
"API key with the name '{}' was created successfully.", | ||
self.name | ||
); | ||
emitln!(out, "Secret key: '{}'", response.key); | ||
Ok(()) | ||
} | ||
println!( | ||
"API key with the name '{}' was created successfully.", | ||
opts.name | ||
); | ||
println!("Secret key: '{}'", response.key); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,29 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use cling::prelude::*; | ||
use prettytable::{row, Table}; | ||
|
||
use crate::args::CommonOptions; | ||
use crate::{emitln, Command}; | ||
|
||
#[derive(Clone, Debug, Parser)] | ||
pub struct List {} | ||
#[derive(CliRunnable, Clone, Debug, Parser)] | ||
#[cling(run = "list")] | ||
pub struct List; | ||
|
||
#[async_trait] | ||
impl Command for List { | ||
async fn run< | ||
A: tokio::io::AsyncWrite + Send + Sync + Unpin, | ||
B: tokio::io::AsyncWrite + Send + Sync + Unpin, | ||
>( | ||
&self, | ||
out: &mut tokio::io::BufWriter<A>, | ||
_err: &mut tokio::io::BufWriter<B>, | ||
common_options: &CommonOptions, | ||
) -> Result<()> { | ||
let client = common_options.new_client()?; | ||
async fn list(common_options: &CommonOptions) -> Result<()> { | ||
let client = common_options.new_client()?; | ||
|
||
let response = cronback_client::api_keys::list(&client).await?; | ||
let response = cronback_client::api_keys::list(&client).await?; | ||
|
||
let response = response.into_inner()?; | ||
// Print Table | ||
if !response.data.is_empty() { | ||
let mut table = Table::new(); | ||
table.set_titles(row!["Id", "Name", "Created At"]); | ||
for key in response.data { | ||
table.add_row(row![ | ||
key.id, | ||
key.name, | ||
key.created_at.to_rfc2822(), | ||
]); | ||
} | ||
|
||
emitln!(out, "{}", table); | ||
let response = response.into_inner()?; | ||
// Print Table | ||
if !response.data.is_empty() { | ||
let mut table = Table::new(); | ||
table.set_titles(row!["Id", "Name", "Created At"]); | ||
for key in response.data { | ||
table.add_row(row![key.id, key.name, key.created_at.to_rfc2822(),]); | ||
} | ||
|
||
Ok(()) | ||
println!("{}", table); | ||
} | ||
|
||
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
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 |
---|---|---|
@@ -1,46 +1,14 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use clap::clap_derive::Parser; | ||
|
||
use crate::args::CommonOptions; | ||
use crate::Command; | ||
use cling::prelude::*; | ||
|
||
mod api_keys; | ||
mod projects; | ||
|
||
#[derive(Parser, Debug, Clone)] | ||
#[derive(CliRunnable, Subcommand, Debug, Clone)] | ||
pub enum AdminCommand { | ||
/// Commands for api key management. This subcommand requires admin | ||
/// privilliages. | ||
ApiKeys { | ||
#[command(subcommand)] | ||
command: api_keys::ApiKeysCommand, | ||
}, | ||
|
||
Projects { | ||
#[command(subcommand)] | ||
command: projects::ProjectsCommand, | ||
}, | ||
} | ||
|
||
#[async_trait] | ||
impl Command for AdminCommand { | ||
async fn run< | ||
A: tokio::io::AsyncWrite + Send + Sync + Unpin, | ||
B: tokio::io::AsyncWrite + Send + Sync + Unpin, | ||
>( | ||
&self, | ||
out: &mut tokio::io::BufWriter<A>, | ||
err: &mut tokio::io::BufWriter<B>, | ||
common_options: &CommonOptions, | ||
) -> Result<()> { | ||
match self { | ||
| AdminCommand::ApiKeys { command } => { | ||
command.run(out, err, common_options).await | ||
} | ||
| AdminCommand::Projects { command } => { | ||
command.run(out, err, common_options).await | ||
} | ||
} | ||
} | ||
#[command(subcommand)] | ||
ApiKeys(api_keys::ApiKeysCommand), | ||
#[command(subcommand)] | ||
Projects(projects::ProjectsCommand), | ||
} |
Oops, something went wrong.