#![cfg_attr(coverage_nightly, allow(unused_features))]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
mod client;
pub mod commands;
use clap::{Parser, Subcommand};
pub use client::{GrpcClient, GrpcClientError};
#[derive(Debug, Parser)]
#[command(name = "reovim-cli")]
#[command(about = "Reovim CLI client (gRPC v2)", long_about = None)]
pub struct CliArgs {
#[arg(long, default_value = "127.0.0.1:12540")]
pub grpc: String,
#[arg(long, short, value_enum, default_value = "plain")]
pub format: OutputFormat,
#[command(subcommand)]
pub command: CliCommand,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum OutputFormat {
Plain,
Json,
}
#[derive(Debug, Subcommand)]
pub enum CliCommand {
Keys {
keys: String,
#[arg(long, short)]
client: u64,
},
Mode {
#[arg(long, short)]
client: u64,
},
Cursor {
#[arg(long, short)]
client: u64,
},
Buffers,
Buffer {
#[arg(long)]
id: Option<u64>,
},
Registers {
name: Option<String>,
},
Capture {
#[arg(long, short)]
client: Option<u64>,
#[arg(long, short = 'f', default_value = "raw_ansi")]
capture_format: String,
#[arg(long)]
web_url: Option<String>,
#[arg(long, default_value = "1920")]
width: u32,
#[arg(long, default_value = "1080")]
height: u32,
#[arg(long, default_value = "1")]
dpr: u32,
#[arg(long, short)]
output: Option<String>,
},
Ping,
Version,
Clients,
ExtensionState {
kind: String,
#[arg(long, short)]
client: u64,
},
Extensions,
}
impl CliArgs {
#[cfg_attr(coverage_nightly, coverage(off))]
pub async fn execute(&self) -> Result<String, GrpcClientError> {
let mut client = GrpcClient::connect(&self.grpc).await?;
match &self.command {
CliCommand::Keys {
keys,
client: target,
} => commands::keys(&mut client, keys, *target, self.format).await,
CliCommand::Mode { client: target } => {
commands::mode(&mut client, *target, self.format).await
}
CliCommand::Cursor { client: target } => {
commands::cursor(&mut client, *target, self.format).await
}
CliCommand::Buffers => commands::buffers(&mut client, self.format).await,
CliCommand::Buffer { id } => commands::buffer(&mut client, *id, self.format).await,
CliCommand::Registers { name } => {
commands::registers(&mut client, name.clone(), self.format).await
}
CliCommand::Capture {
client: client_id,
capture_format,
web_url,
width,
height,
dpr,
output,
} => {
let address = &self.grpc;
commands::capture(
&mut client,
*client_id,
capture_format,
web_url.as_deref(),
address,
*width,
*height,
*dpr,
output.as_deref(),
self.format,
)
.await
}
CliCommand::Ping => commands::ping(&mut client, self.format).await,
CliCommand::Version => commands::version(&mut client, self.format).await,
CliCommand::Clients => commands::clients(&mut client, self.format).await,
CliCommand::ExtensionState {
kind,
client: target,
} => commands::extension_state(&mut client, kind, *target, self.format).await,
CliCommand::Extensions => commands::extensions(&mut client, self.format).await,
}
}
}
#[cfg(test)]
#[path = "lib_tests.rs"]
mod tests;