Karma CLI Parsing SDK For C#
ktools-csharp/kcli/README.mdkcli is a small C# SDK for building structured command-line interfaces.
It supports the same two CLI shapes used elsewhere in the ktools stack:
- top-level options such as
--verbose - inline roots such as
--trace-*,--config-*, and--build-*
The C# API keeps the same conceptual model as the existing C++ and Java implementations while using .NET-style naming.
Quick Start
using Kcli;
Parser parser = new Parser();
InlineParser build = new InlineParser("--build");
build.SetHandler("-profile", (context, value) => {
}, "Set build profile.");
parser.AddInlineParser(build);
parser.AddAlias("-v", "--verbose");
parser.SetHandler("--verbose", context => {
}, "Enable verbose logging.");
parser.ParseOrExit(args);
Documentation
Behavior Highlights
- The full command line is validated before any registered handler runs.
ParseOrExit()prints[error] [cli] ...tostderrand exits with code2.ParseOrThrow()raisesCliError.- Bare inline roots print inline help when no root value is provided.
- Required values may consume an option-like first token.
- Literal
--remains an unknown option; it is not treated as a separator.
Build
kbuild --build-latest
SDK output:
build/latest/sdk/lib/Kcli.dllbuild/latest/tests/bin/Kcli.Tests.dll
Build And Run Demos
# Builds the SDK plus demos listed in .kbuild.json build.defaults.demos.
kbuild --build-latest
# Explicit demo-only run.
kbuild --build-demos
Demo directories:
- Bootstrap compile/link check:
demo/bootstrap/ - SDK demos:
demo/sdk/{alpha,beta,gamma} - Executable demos:
demo/exe/{core,omega}
Useful demo commands:
./demo/exe/core/build/latest/test
./demo/exe/core/build/latest/test --alpha
./demo/exe/core/build/latest/test --alpha-message "hello"
./demo/exe/core/build/latest/test --output stdout
./demo/exe/omega/build/latest/test --beta-workers 8
./demo/exe/omega/build/latest/test --newgamma-tag "prod"
./demo/exe/omega/build/latest/test --build
Run Tests
dotnet build/latest/tests/bin/Kcli.Tests.dll
Layout
- Public API and implementation:
src/ - API tests:
tests/src/ - Demo builds:
demo/
Working references:
src/Kcli/Parser.cssrc/Kcli/InlineParser.cssrc/Kcli/ParseEngine.cstests/src/Kcli.Tests/Program.csdemo/sdk/alpha/src/Kcli/Demo/Alpha/AlphaSdk.csdemo/exe/core/src/Kcli/Demo/Core/Program.csdemo/exe/omega/src/Kcli/Demo/Omega/Program.cs