Private
Public Access
1
0
Files
Kordophone/kpcli/src/main.rs

51 lines
1.1 KiB
Rust
Raw Normal View History

mod client_cli;
mod printers;
2024-11-09 17:35:39 -08:00
use clap::{Parser, Subcommand};
use client_cli::ClientCli;
2024-11-09 17:35:39 -08:00
/// A command line interface for the Kordophone library and daemon
2024-11-09 17:35:39 -08:00
#[derive(Parser)]
#[command(name = "kpcli")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Commands for api client operations
Client {
#[command(subcommand)]
command: ClientCommands,
},
}
#[derive(Subcommand)]
enum ClientCommands {
/// Prints all known conversations on the server.
Conversations,
/// Prints the server Kordophone version.
2024-11-09 17:35:39 -08:00
Version,
}
async fn run_command(command: Commands) -> Result<(), Box<dyn std::error::Error>> {
let mut client = ClientCli::new();
match command {
2024-11-09 17:35:39 -08:00
Commands::Client { command } => match command {
ClientCommands::Version => client.print_version().await,
ClientCommands::Conversations => client.print_conversations().await,
2024-11-09 17:35:39 -08:00
},
}
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
run_command(cli.command).await
.map_err(|e| log::error!("Error: {}", e))
.err();
}