Cohesive Systems logoCOHESIVE SYSTEMS

Building Blocks

Cohesive.Cli

Cohesive Cli icon

Cohesive.Cli builds command-line applications in a declarative, Minimal-API-style shape while reusing Cohesive.Configuration and host-backed dependency injection.

CLI invocations become another entrypoint into the same application configuration, dependency graph, validation pipeline, and execution model used by APIs, workers, process runtimes, and local tools.

Why It Exists

Products often need APIs, workers, local developer tools, migration commands, admin commands, test harnesses, and training job runners. Those surfaces drift when CLI parsing, appsettings, environment variables, profiles, and service activation are implemented separately.

Cohesive.Cli treats command-line values as a final input into the same configuration pipeline as the rest of the app.

Command Declaration

A CLI application is declared as a command tree. Commands bind typed configuration, declare options and arguments, attach validators, add middleware, and register handlers.

The shape is intentionally close to Minimal APIs: declare the app, map commands, bind typed input, compose middleware, and run.

Parameter Binding

Parameters come from Cohesive.Configuration metadata. The same parameter definition can drive command-line options, positional arguments, environment-variable binding, appsettings binding, required-value checks, allowed values, time unit conversion, and collection parsing.

Host-Backed Execution

Cohesive.Cli can start an application host for a command invocation, attach its service provider to the command context, execute the handler, and stop the host.

Handlers can ask for typed configuration, command context, cancellation tokens, output writers, configuration roots, parse results, or DI-backed services.

Testing and Output

Structured output helpers provide stdout, stderr, and JSON serialization. A test harness can invoke commands with captured output and exit codes, allowing in-memory configuration, fake services, and deterministic CLI tests without shelling out to a separate process.