Skip to main content

custom_cli/
custom_cli.rs

1//! Example: Custom CLI with individual linters
2//!
3//! This example shows how to create a custom CLI that uses individual
4//! linter functions from the torrust-linting package.
5
6use anyhow::Result;
7use clap::{Parser, Subcommand};
8use torrust_linting::{
9    run_clippy_linter, run_markdown_linter, run_rustfmt_linter, run_shellcheck_linter, run_toml_linter, run_yaml_linter,
10};
11
12#[derive(Parser)]
13#[command(name = "custom-linter")]
14#[command(about = "A custom linter CLI using torrust-linting")]
15struct Cli {
16    #[command(subcommand)]
17    command: Commands,
18}
19
20#[derive(Subcommand)]
21enum Commands {
22    /// Lint only Rust code (clippy + rustfmt)
23    Rust,
24    /// Lint only markup files (markdown + yaml + toml)
25    Markup,
26    /// Lint only shell scripts
27    Shell,
28}
29
30fn main() -> Result<()> {
31    // Initialize logging (you can customize this)
32    torrust_linting::init_tracing();
33
34    let cli = Cli::parse();
35
36    match cli.command {
37        Commands::Rust => {
38            println!("🦀 Running Rust linters...");
39            run_clippy_linter()?;
40            run_rustfmt_linter()?;
41        }
42        Commands::Markup => {
43            println!("📄 Running markup linters...");
44            run_markdown_linter()?;
45            run_yaml_linter()?;
46            run_toml_linter()?;
47        }
48        Commands::Shell => {
49            println!("🐚 Running shell script linter...");
50            run_shellcheck_linter()?;
51        }
52    }
53
54    println!("✅ All selected linters passed!");
55    Ok(())
56}