| Crates.io | workhelix-cli-common |
| lib.rs | workhelix-cli-common |
| version | 0.4.1 |
| created_at | 2025-10-13 02:47:24.513274+00 |
| updated_at | 2025-10-21 12:14:37.958611+00 |
| description | Common functionality for Workhelix Rust CLI tools |
| homepage | |
| repository | https://github.com/tftio/workhelix-cli-common |
| max_upload_size | |
| id | 1879938 |
| size | 72,068 |
Common functionality for Workhelix Rust CLI tools.
This library provides shared functionality for CLI tools including:
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-common
For 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.