dynamic-cli 0.7.0

A framework for building configurable CLI and REPL applications from YAML/JSON configuration files
Documentation
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# dynamic-cli

[![Crates.io](https://img.shields.io/crates/v/dynamic-cli.svg)](https://crates.io/crates/dynamic-cli)
[![codecov](https://codecov.io/gh/biface/dcli/graph/badge.svg?token=58T5WKC802)](https://codecov.io/gh/biface/dcli)
[![Documentation](https://docs.rs/dynamic-cli/badge.svg)](https://docs.rs/dynamic-cli)
[![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](LICENSE-MIT)

A powerful Rust framework for creating configurable CLI and REPL applications via YAML/JSON files.

**Define your command-line interface in a configuration file, not in code.** ✨

---

**English** | **[FranΓ§ais]README.fr.md**

---

## 🎯 Features

- **πŸ“ Configuration-Driven** : Define commands, arguments and options in YAML/JSON
- **πŸ”„ CLI, REPL & Batch Modes** : Command-line, interactive, and scripted batch execution
- **βœ… Automatic Validation** : Built-in type checking and constraint validation
- **🎨 Rich Error Messages** : Colorful and informative messages with suggestions
- **πŸ”Œ Plugin System** : Granular static plugins (help, version, exit, sysinfo, env, config β€”
  compose only what you need) and sandboxed WASM plugins (loaded at runtime)
- **πŸ“š Well Documented** : Complete API documentation and examples
- **πŸ§ͺ Thoroughly Tested** : Extensive test coverage
- **⚑ Performance** : Zero-cost abstractions with efficient parsing

---

## πŸš€ Quick Start

### Installation

Add to your `Cargo.toml`:

```toml
[dependencies]
dynamic-cli = "0.7.0"

# Optional β€” sandboxed WASM plugins (see Plugin System below)
# dynamic-cli = { version = "0.7.0", features = ["wasm-plugins"] }
```

### Basic Example

**1. Create a configuration file** (`commands.yaml`):

```yaml
metadata:
  version: "1.0.0"
  prompt: "myapp"
  prompt_suffix: " > "

commands:
  - name: greet
    aliases: [hello, hi]
    description: "Greet someone"
    required: false
    arguments:
      - name: name
        arg_type: string
        required: true
        description: "Name to greet"
        validation: []
    options:
      - name: loud
        short: l
        long: loud
        option_type: bool
        required: false
        description: "Use uppercase"
        choices: []
    implementation: "greet_handler"

global_options: []
```
> Note :
> 
> The proper syntax for the configuration file is available in [the project repository]CONFIG_SYNTAX_REFERENCE.md.  

**2. Implement your command handlers**:

```rust
use dynamic_cli::prelude::*;

// Define your application context
#[derive(Default)]
struct MyContext {
    // Your application state
}

impl ExecutionContext for MyContext {
    fn as_any(&self) -> &dyn std::any::Any { self }
    fn as_any_mut(&mut self) -> &mut dyn std::any::Any { self }
}

// Implement the command handler
struct GreetCommand;

impl CommandHandler for GreetCommand {
    fn execute(
        &self,
        _context: &mut dyn ExecutionContext,
        args: &ParsedArgs,
    ) -> dynamic_cli::Result<()> {
        let name = args.get_scalar("name").unwrap();
        let loud = args.get_scalar("loud").map(|v| v == "true").unwrap_or(false);
        
        let greeting = format!("Hello, {}!", name);
        println!("{}", if loud { greeting.to_uppercase() } else { greeting });
        
        Ok(())
    }
}

fn main() -> dynamic_cli::Result<()> {
    CliBuilder::new()
        .config_file("commands.yaml")
        .context(Box::new(MyContext::default()))
        .register_sync_handler("greet_handler", Box::new(GreetCommand))
        .build()?
        .run()
}
```

**3. Run your application**:

```bash
# CLI mode
$ myapp greet Alice
Hello, Alice!

$ myapp greet Bob --loud
HELLO, BOB!

# REPL mode
$ myapp
myapp > greet Alice
Hello, Alice!
myapp > help
Available commands:
  greet [name] - Greet someone
myapp > exit
```

**Batch mode** β€” run a whole file of commands, one per line (blank lines and
`#`-prefixed comments are skipped):

```rust, ignore
let outcome = app.run_script("commands.txt", ScriptErrorPolicy::Continue)?;
println!("{}/{} succeeded", outcome.lines_succeeded, outcome.lines_executed);
```

The same file can also be loaded from inside an already-running REPL
session with `:load commands.txt`.

---

## πŸ”Œ Plugin System

Extend an application with handlers that do not live in your own crate,
without modifying `dynamic-cli` itself. Two mechanisms are available:

| Mechanism                           | When to use it                                  | Cost                                                            |
|-------------------------------------|-------------------------------------------------|-----------------------------------------------------------------|
| **Static plugins** (`Plugin` trait) | Compiled into your binary                       | No `unsafe`, no extra dependency                                |
| **WASM plugins** (`WasmPlugin`)     | Distributed and loaded independently, sandboxed | `wasmtime` dependency, opt-in via `features = ["wasm-plugins"]` |

`dynamic-cli` ships `SystemPlugin` out of the box β€” `help`, `version`, and
`exit` in one call:

```rust, ignore
use dynamic_cli::plugin::SystemPlugin;

CliBuilder::new()
    .config_file("commands.yaml")
    .context(Box::new(MyContext::default()))
    .register_plugin(Box::new(SystemPlugin::new()))
    .register_sync_handler("greet_handler", Box::new(GreetCommand))
    .build()?
    .run()
```

Each of `help`/`version`/`exit` is also available as its own independent
plugin (`HelpPlugin`, `VersionPlugin`, `ExitPlugin`) β€” register only the one
you need instead of the bundle. Three more, feature-gated, cover common
introspection needs: `SysInfoPlugin` (`sysinfo-plugin`, OS/architecture/
parallelism), `EnvPlugin` (`env-plugin`, filtered environment variables β€”
sensitive-looking ones hidden by default), and `ConfigPlugin`
(`config-plugin`, show/re-validate the loaded YAML config without
restarting):

```rust, ignore
use dynamic_cli::plugin::{ConfigPlugin, SysInfoPlugin};

CliBuilder::new()
    .config_file("commands.yaml")
    .context(Box::new(MyContext::default()))
    .register_plugin(Box::new(SysInfoPlugin::new()))
    .register_plugin(Box::new(ConfigPlugin::new().with_config(config)))
    .build()?
    .run()
```

WASM plugins run in a `wasmtime` sandbox, with no `unsafe` code on the host
side:

```rust, ignore
CliBuilder::new()
    .config_file("commands.yaml")
    .context(Box::new(MyContext::default()))
    .register_wasm_plugin(
        Path::new("plugins/greet.wasm"),
        &[("greet_hello", "say_hello")],
    )?
    .build()?
    .run()
```

Static and WASM plugins, and directly-registered handlers, all coexist in
the same application β€” the YAML configuration remains the single source of
truth for command definitions either way.

**[Full Plugin Guide β†’](PLUGIN_GUIDE.md)** ([FranΓ§ais](PLUGIN_GUIDE.fr.md)) β€”
the complete WASM ABI contract for third-party plugin authors, a worked
example, and the architecture decision behind it
([DD-021](https://github.com/biface/dcli/issues/10)).

---

## πŸ“– Documentation

- **[API Reference]https://docs.rs/dynamic-cli** - Complete API documentation
- **[Examples]examples/README.md** - Working examples and code samples
- **[Contributing Guide]CONTRIBUTING.md** - How to contribute to the project

---

## πŸŽ“ Examples

The [examples directory](examples) contains complete examples:

- **[simple_calculator.rs]examples/simple_calculator.rs** - Basic arithmetic calculator
- **[rpn_calculator.rs]examples/rpn_calculator.rs** - Reverse Polish Notation calculator
- **[advanced_rpn_calculator.rs]examples/advanced_rpn_calculator.rs** - HP-41CX-flavored RPN calculator with scientific functions, memory registers, `SysInfoPlugin`/`ConfigPlugin`, and batch/`:load` execution
- **[file_manager.rs]examples/file_manager.rs** - File operations with validation
- **[task_runner.rs]examples/task_runner.rs** - Task management application
- **[async_token_demo.rs]examples/async_token_demo.rs** - Async command handler demo

Run any example:
```bash
cargo run --example simple_calculator

# advanced_rpn_calculator needs its two feature flags:
cargo run --example advanced_rpn_calculator --features sysinfo-plugin,config-plugin
```

---

## πŸ— Architecture

dynamic-cli is organized into focused modules:

- **config** - Configuration loading and validation
- **context** - Execution context trait
- **executor** - Command execution engine
- **registry** - Command and handler registry
- **parser** - CLI and REPL argument parsing
- **validator** - Argument validation
- **interface** - CLI and REPL interfaces
- **error** - Error types and display
- **builder** - Fluent API for building applications
- **help** - Dynamic `--help` generation
- **plugin** - Granular static plugins (`plugin::builtin`: help, version, exit, sysinfo, env, config) and sandboxed WASM (`wasm-plugins` feature) extension mechanisms

---

## πŸ§ͺ Tests

```bash
# Run all tests (default features)
cargo test

# Run all tests, across every feature flag
cargo test --all-features

# Run with coverage
cargo llvm-cov --all-targets --all-features --workspace

# Check code quality
cargo clippy --all-features -- -D warnings
```

**Current test statistics:**

- **500+ unit tests** βœ…
- **230+ documentation tests**
- **12 integration tests** (static + WASM plugins, full public API chain)
- **80-90% code coverage** *(not re-measured for v0.7.0 β€” `cargo-llvm-cov` wasn't run this sprint)*
- **Zero clippy warnings**, confirmed across `--all-features`
  (`wasm-plugins`, `sysinfo-plugin`, `env-plugin`, `config-plugin` combined)

---

## 🀝 Contributing

We welcome contributions from everyone! Here's how you can help:

### Ways to Contribute

- πŸ› **Report bugs** - Found a bug? [Open an issue]https://github.com/biface/dcli/issues
- πŸ’‘ **Suggest features** - Have an idea? [Start a discussion]https://github.com/biface/dcli/discussions
- πŸ“ **Improve documentation** - Fix typos, clarify, add examples
- πŸ”§ **Submit code** - Fix bugs, implement features, improve performance
- πŸ§ͺ **Add tests** - Increase coverage, add edge cases

### Getting Started

```bash
# Fork and clone
git clone https://github.com/biface/dcli.git
cd dynamic-cli

# Create a branch
git checkout -b feature/my-feature

# Make your changes and test
cargo test --all-features
cargo clippy --all-features

# Commit and push
git commit -am "Add awesome feature"
git push origin feature/my-feature
```

### Development Guidelines

**Before submitting a pull request:**

- [ ] Code follows Rust style guidelines (`cargo fmt`)
- [ ] All tests pass (`cargo test --all-features`)
- [ ] No clippy warnings (`cargo clippy --all-features -- -D warnings`)
- [ ] Documentation is updated
- [ ] New tests added for new features
- [ ] Commit messages are clear and descriptive

### Code of Conduct

This project follows a Code of Conduct to ensure a welcoming environment:

- βœ… Be respectful to others
- βœ… Welcome newcomers and help them learn
- βœ… Constructive criticism helps us move forward and improveβ€”let's embrace it
- βœ… Focus on what's best for the community
- ❌ No harassment, trolling or personal attacks

**[Read the complete contributing guide β†’](CONTRIBUTING.md)**

---

## πŸ“œ License

Licensed under your choice of:

 * Apache License, Version 2.0
   ([LICENSE-APACHE]LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license
   ([LICENSE-MIT]LICENSE-MIT or http://opensource.org/licenses/MIT)

### Contribution Licensing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

---

## πŸ™ Acknowledgments

- **Rust Community** - For the amazing tools and libraries developed
- **Contributors** - Everyone who has contributed to this project
- **[clap]https://github.com/clap-rs/clap** - Inspiration for CLI design
- **[rustyline]https://github.com/kkawakam/rustyline** - REPL functionality
- **[serde]https://github.com/serde-rs/serde** - Serialization support

---

## πŸ“ž Support

**Need help?**

- πŸ“– Check the [API documentation]https://docs.rs/dynamic-cli
- πŸ’¬ Open a [discussion]https://github.com/biface/dcli/discussions
- πŸ› Report an [issue]https://github.com/biface/dcli/issues
- πŸ“§ Contact the maintainers

**Found a security vulnerability?**  
Please report it privately to the maintainers.

---

## 🌟 Show Your Support

If you find dynamic-cli useful, please:

- ⭐ **Star the repository** on GitHub
- πŸ“’ **Share** it with others who might find it useful
- πŸ“ **Write** a blog post or tutorial!

**Last updated**: 2026-08-23