Skip to main content

clap_noun_verb/cli/
mod.rs

1// Copyright (c) 2024 Sean Chatman
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! CLI layer - argument validation and routing only
5//!
6//! This module contains the CLI interface layer that validates arguments
7//! and delegates to business logic. It contains NO business logic.
8//!
9//! ## Design Principle
10//!
11//! CLI code ONLY validates arguments and options, then delegates to
12//! business logic functions. No business logic is allowed in this layer.
13
14pub mod builder;
15pub mod preprocessor;
16pub mod registry;
17pub mod router;
18pub mod validator;
19pub(crate) mod value_parser;
20
21// Scaffolding and project initialization
22pub mod init;
23
24pub use builder::CliBuilder;
25pub use init::scaffold_config;
26pub use registry::CommandRegistry;
27pub use router::CommandRouter;
28pub use validator::ArgValidator;
29
30/// Auto-run CLI with all registered commands
31///
32/// This function automatically discovers all functions marked with
33/// `#[verb]` attributes and runs the CLI.
34///
35/// These attribute macros are provided by the `clap-noun-verb-macros` crate.
36pub fn run() -> crate::error::Result<()> {
37    let registry = registry::CommandRegistry::get();
38    let registry = registry.lock().map_err(|e| {
39        crate::error::NounVerbError::execution_error(format!("Failed to lock registry: {}", e))
40    })?;
41    let args: Vec<String> = std::env::args().collect();
42    registry.run(args)
43}