Common functionality for Workhelix Rust CLI tools.
This library provides shared functionality for CLI tools including:
- Shell completion generation - Generate completions for bash, zsh, fish, elvish, PowerShell
- Health check framework - Extensible doctor command with tool-specific checks
- License display - Standardized license information for MIT, Apache-2.0, CC0
- Terminal output utilities - TTY-aware colored output and formatting
Add to your Cargo.toml:
[dependencies]
workhelix-cli-common = "0.1"
clap = { version = "4.5", features = ["derive"] }
clap_complete = "4.5"Or add via command line:
cargo add workhelix-cli-commonFor local development:
[dependencies]
workhelix-cli-common = { path = "../workhelix-cli-common" }use workhelix_cli_common::{
RepoInfo, DoctorChecks, DoctorCheck,
completions, doctor, license, LicenseType,
};
use clap::{Parser, Subcommand};
#[derive(Parser)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Version,
License,
Completions { shell: clap_complete::Shell },
Doctor,
}
struct MyTool;
impl DoctorChecks for MyTool {
fn repo_info() -> RepoInfo {
RepoInfo::new("myorg", "mytool")
}
fn current_version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
fn tool_checks(&self) -> Vec<DoctorCheck> {
vec![
DoctorCheck::file_exists("~/.config/mytool/config.toml"),
]
}
}
fn main() {
let cli = Cli::parse();
let exit_code = match cli.command {
Commands::Version => {
println!("mytool {}", env!("CARGO_PKG_VERSION"));
0
}
Commands::License => {
println!("{}", license::display_license("mytool", LicenseType::MIT));
0
}
Commands::Completions { shell } => {
completions::generate_completions::<Cli>(shell);
0
}
Commands::Doctor => {
doctor::run_doctor(&MyTool)
}
};
std::process::exit(exit_code);
}Generate shell completions with installation instructions:
completions::generate_completions::<YourCli>(Shell::Bash);Health checks with extensible framework:
impl DoctorChecks for MyTool {
fn repo_info() -> RepoInfo {
RepoInfo::new("owner", "repo")
}
fn current_version() -> &'static str {
"1.0.0"
}
fn tool_checks(&self) -> Vec<DoctorCheck> {
vec![
DoctorCheck::file_exists("/path/to/config"),
DoctorCheck::dir_exists("/path/to/data"),
]
}
}
let tool = MyTool;
doctor::run_doctor(&tool);Display license information:
use workhelix_cli_common::{license, LicenseType};
println!("{}", license::display_license("mytool", LicenseType::MIT));TTY-aware colored output:
use workhelix_cli_common::output;
println!("{}", output::success("Operation completed"));
println!("{}", output::error("Operation failed"));
println!("{}", output::warning("Warning message"));
println!("{}", output::info("Information"));See RELEASE.md for information about the release process.
MIT License - See LICENSE file for details.