Skip to main content

bito_lint/
lib.rs

1//! Library interface for the `bito-lint` CLI.
2//!
3//! This crate exposes the CLI's argument parser and command structure as a library,
4//! primarily for documentation generation and testing. The actual entry point is
5//! in `main.rs`.
6//!
7//! # Structure
8//!
9//! - [`Cli`] - The root argument parser (clap derive)
10//! - [`Commands`] - Available subcommands
11//! - [`commands`] - Command implementations
12//!
13//! # Documentation Generation
14//!
15//! The [`command()`] function returns the clap `Command` for generating man pages
16//! and shell completions via `xtask`.
17
18pub mod commands;
19
20#[cfg(feature = "mcp")]
21pub mod server;
22
23use clap::{CommandFactory, Parser, Subcommand};
24use std::path::PathBuf;
25
26/// Color output preference.
27#[derive(Debug, Clone, Copy, Default, clap::ValueEnum)]
28pub enum ColorChoice {
29    /// Detect terminal capabilities automatically.
30    #[default]
31    Auto,
32    /// Always emit colors.
33    Always,
34    /// Never emit colors.
35    Never,
36}
37
38impl ColorChoice {
39    /// Configure global color output based on this choice.
40    ///
41    /// Call this once at startup to set the color mode.
42    pub fn apply(self) {
43        match self {
44            Self::Auto => {} // owo-colors auto-detects by default
45            Self::Always => owo_colors::set_override(true),
46            Self::Never => owo_colors::set_override(false),
47        }
48    }
49}
50
51const ENV_HELP: &str = "\
52ENVIRONMENT VARIABLES:
53    RUST_LOG               Log filter (e.g., debug, bito-lint=trace)
54    BITO_LINT_LOG_PATH     Explicit log file path
55    BITO_LINT_LOG_DIR      Log directory
56";
57/// Command-line interface definition for bito-lint.
58#[derive(Parser)]
59#[command(name = "bito-lint")]
60#[command(about = "Quality gate tooling for building-in-the-open artifacts", long_about = None)]
61#[command(version)]
62#[command(after_long_help = ENV_HELP)]
63pub struct Cli {
64    /// The subcommand to execute.
65    #[command(subcommand)]
66    pub command: Commands,
67
68    /// Path to configuration file (overrides discovery)
69    #[arg(short, long, global = true, value_name = "FILE")]
70    pub config: Option<PathBuf>,
71
72    /// Run as if started in DIR
73    #[arg(short = 'C', long, global = true)]
74    pub chdir: Option<PathBuf>,
75
76    /// Only print errors (suppresses warnings/info)
77    #[arg(short, long, global = true)]
78    pub quiet: bool,
79
80    /// More detail (repeatable; e.g. -vv)
81    #[arg(short, long, global = true, action = clap::ArgAction::Count)]
82    pub verbose: u8,
83
84    /// Colorize output
85    #[arg(long, global = true, value_enum, default_value_t)]
86    pub color: ColorChoice,
87
88    /// Output as JSON (for scripting)
89    #[arg(long, global = true)]
90    pub json: bool,
91}
92
93/// Available subcommands for the CLI.
94#[derive(Subcommand)]
95pub enum Commands {
96    /// Run comprehensive writing analysis
97    Analyze(commands::analyze::AnalyzeArgs),
98
99    /// Count tokens in a file
100    Tokens(commands::tokens::TokensArgs),
101
102    /// Score readability (Flesch-Kincaid Grade Level)
103    Readability(commands::readability::ReadabilityArgs),
104
105    /// Check document completeness against a template
106    Completeness(commands::completeness::CompletenessArgs),
107
108    /// Check grammar and passive voice
109    Grammar(commands::grammar::GrammarArgs),
110
111    /// Diagnose configuration and environment
112    Doctor(commands::doctor::DoctorArgs),
113
114    /// Show package information
115    Info(commands::info::InfoArgs),
116
117    /// Start MCP (Model Context Protocol) server on stdio
118    #[cfg(feature = "mcp")]
119    Serve(commands::serve::ServeArgs),
120}
121
122/// Returns the clap command for documentation generation
123pub fn command() -> clap::Command {
124    Cli::command()
125}