diff --git a/kpcli/src/client_cli.rs b/kpcli/src/client/mod.rs similarity index 71% rename from kpcli/src/client_cli.rs rename to kpcli/src/client/mod.rs index 33a56ac..8e35fa5 100644 --- a/kpcli/src/client_cli.rs +++ b/kpcli/src/client/mod.rs @@ -3,9 +3,29 @@ use kordophone::api::http_client::HTTPAPIClient; use kordophone::api::http_client::Credentials; use dotenv; +use clap::Subcommand; 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> { + let mut client = ClientCli::new(); + match cmd { + Commands::Version => client.print_version().await, + Commands::Conversations => client.print_conversations().await, + } + } +} + +struct ClientCli { api: HTTPAPIClient, } diff --git a/kpcli/src/main.rs b/kpcli/src/main.rs index c1ff3bb..c668088 100644 --- a/kpcli/src/main.rs +++ b/kpcli/src/main.rs @@ -1,8 +1,6 @@ -mod client_cli; mod printers; - +mod client; use clap::{Parser, Subcommand}; -use client_cli::ClientCli; /// A command line interface for the Kordophone library and daemon #[derive(Parser)] @@ -17,26 +15,13 @@ enum Commands { /// Commands for api client operations Client { #[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> { - let mut client = ClientCli::new(); match command { - Commands::Client { command } => match command { - ClientCommands::Version => client.print_version().await, - ClientCommands::Conversations => client.print_conversations().await, - }, + Commands::Client { command } => client::Commands::run(command).await, } }