kpcli: reorg subcommands
This commit is contained in:
@@ -3,9 +3,29 @@ use kordophone::api::http_client::HTTPAPIClient;
|
|||||||
use kordophone::api::http_client::Credentials;
|
use kordophone::api::http_client::Credentials;
|
||||||
|
|
||||||
use dotenv;
|
use dotenv;
|
||||||
|
use clap::Subcommand;
|
||||||
use crate::printers::ConversationPrinter;
|
use crate::printers::ConversationPrinter;
|
||||||
|
|
||||||
pub struct ClientCli {
|
#[derive(Subcommand)]
|
||||||
|
pub enum Commands {
|
||||||
|
/// Prints all known conversations on the server.
|
||||||
|
Conversations,
|
||||||
|
|
||||||
|
/// Prints the server Kordophone version.
|
||||||
|
Version,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Commands {
|
||||||
|
pub async fn run(cmd: Commands) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let mut client = ClientCli::new();
|
||||||
|
match cmd {
|
||||||
|
Commands::Version => client.print_version().await,
|
||||||
|
Commands::Conversations => client.print_conversations().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ClientCli {
|
||||||
api: HTTPAPIClient,
|
api: HTTPAPIClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
mod client_cli;
|
|
||||||
mod printers;
|
mod printers;
|
||||||
|
mod client;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use client_cli::ClientCli;
|
|
||||||
|
|
||||||
/// A command line interface for the Kordophone library and daemon
|
/// A command line interface for the Kordophone library and daemon
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
@@ -17,26 +15,13 @@ enum Commands {
|
|||||||
/// Commands for api client operations
|
/// Commands for api client operations
|
||||||
Client {
|
Client {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: ClientCommands,
|
command: client::Commands,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
|
||||||
enum ClientCommands {
|
|
||||||
/// Prints all known conversations on the server.
|
|
||||||
Conversations,
|
|
||||||
|
|
||||||
/// Prints the server Kordophone version.
|
|
||||||
Version,
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn run_command(command: Commands) -> Result<(), Box<dyn std::error::Error>> {
|
async fn run_command(command: Commands) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut client = ClientCli::new();
|
|
||||||
match command {
|
match command {
|
||||||
Commands::Client { command } => match command {
|
Commands::Client { command } => client::Commands::run(command).await,
|
||||||
ClientCommands::Version => client.print_version().await,
|
|
||||||
ClientCommands::Conversations => client.print_conversations().await,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user