1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! CLI dispatch and integration for clap-based applications.
//!
//! This module bridges Standout's rendering engine with clap's argument parsing,
//! letting you focus on command logic while Standout handles output formatting,
//! help rendering, and structured output modes (JSON, YAML, etc.).
//!
//! ## When to Use This Module
//!
//! - You have a clap-based CLI and want rich, testable output
//! - You need `--output=json` support without manual serialization
//! - You want styled help with topic pages
//! - You're adopting Standout incrementally (one command at a time)
//!
//! If you only need template rendering without CLI integration, use the
//! [`render`](crate::render) functions directly.
//!
//! ## Single-Threaded Design
//!
//! CLI applications are single-threaded: parse args → run one handler → output → exit.
//! Handlers use `&mut self` and `FnMut`, allowing natural Rust patterns without
//! forcing interior mutability wrappers (`Arc<Mutex<_>>`).
//!
//! ```rust,ignore
//! use standout::cli::{App, Output};
//!
//! struct MyApi {
//! index: HashMap<Uuid, Item>,
//! }
//!
//! impl MyApi {
//! fn add(&mut self, item: Item) { self.index.insert(item.id, item); }
//! }
//!
//! let mut api = MyApi::new();
//!
//! // FnMut handlers can capture mutable state
//! App::new()
//! .command("add", |m, ctx| {
//! let item = Item::from(m);
//! api.add(item); // &mut self works!
//! Ok(Output::Silent)
//! }, "")?
//! .build()?
//! .run(cmd, args);
//! ```
//!
//! ## Execution Flow
//!
//! Standout follows a linear pipeline from CLI input to rendered output:
//!
//! ```text
//! Clap Parsing → Dispatch → Handler → Hooks → Rendering → Output
//! ```
//!
//! 1. Parsing: Your clap Command is augmented with Standout's flags
//! (`--output`, `--output-file-path`) and parsed normally.
//!
//! 2. Dispatch: Standout extracts the command path from ArgMatches,
//! navigating through subcommands to find the registered handler.
//!
//! 3. Handler: Your logic executes, returning [`Output`] (data to render,
//! silent, or binary). Errors propagate via `?`.
//!
//! 4. Hooks: Optional hooks run at three points: pre-dispatch (validation),
//! post-dispatch (data transformation), post-output (output transformation).
//!
//! 5. Rendering: Data flows through the template engine, applying styles.
//! Structured modes (JSON, YAML) skip templating and serialize directly.
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use standout::cli::{App, Output, HandlerResult};
//!
//! App::new()
//! .command("list", |matches, ctx| {
//! let items = load_items()?;
//! Ok(Output::Render(items))
//! }, "{% for item in items %}{{ item }}\n{% endfor %}")?
//! .build()?
//! .run(cmd, std::env::args());
//! ```
//!
//! ## Partial Adoption
//!
//! Standout doesn't require all-or-nothing adoption. Register only the
//! commands you want Standout to handle; unmatched commands return
//! [`RunResult::NoMatch`] with the ArgMatches for your own dispatch:
//!
//! ```rust,ignore
//! match app.run_to_string(cmd, args) {
//! RunResult::Handled(output) => println!("{}", output),
//! RunResult::NoMatch(matches) => legacy_dispatch(matches),
//! RunResult::Binary(bytes, filename) => std::fs::write(filename, bytes)?,
//! }
//! ```
//!
//! ## Key Types
//!
//! - [`App`]: Main entry point and configuration (re-export of `AppBuilder`)
//! - [`Handler`]: Trait for command handlers (`&mut self`)
//! - [`FnHandler`]: Wrapper for `FnMut` closures
//! - [`Output`]: What handlers produce (render data, silent, binary)
//! - [`HandlerResult`]: `Result<Output<T>, Error>` — enables `?` for error handling
//! - [`RunResult`]: Dispatch outcome (handled, binary, or no match)
//! - [`Hooks`]: Pre/post execution hooks for validation and transformation
//! - [`CommandContext`]: Runtime info passed to handlers (command path, app state)
//!
//! ## See Also
//!
//! - [`crate::render`]: Direct rendering without CLI integration
//! - [`handler`]: Handler types and the Handler trait
//! - [`hooks`]: Hook system for intercepting execution
//! - [`help`]: Help rendering and topic system
// Internal modules
// Helper functions (formerly the App struct lived here)
pub
// Builder is now the single App implementation
// Public modules
// Re-export AppBuilder as App — the single unified type
pub use AppBuilder as App;
// Re-export group types for declarative dispatch
pub use ;
// Re-export result type
pub use HelpResult;
// Re-export help types
pub use ;
// Re-export handler types
pub use ;
// Re-export hook types
pub use ;
// Re-export derive macros from standout-macros
pub use Dispatch;
// Re-export error types
pub use crateSetupError;
// Re-export dispatch utilities from standout-dispatch
pub use ;
/// Parses a clap command with styled help output.
///
/// This is the simplest entry point for basic CLIs without topics.
/// Like `parse`, but takes arguments from an iterator.