Private
Public Access
1
0

kpcli: reorg subcommands

This commit is contained in:
2024-12-08 15:08:15 -08:00
parent 0e8b8f339a
commit 75d4767009
2 changed files with 24 additions and 19 deletions

View File

@@ -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<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,
}

View File

@@ -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<dyn std::error::Error>> {
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,
}
}