args library Core
Command-line argument parsing and command runners for Artisanal.
This library provides CommandRunner and Command which extend
package:args to provide a polished CLI experience with:
- Automatic help generation with Lip Gloss styling.
- Support for subcommands and nested command structures.
- Integration with Console for verbosity-aware output.
- Custom usage formatting and command listing.
Command Runner
The CommandRunner orchestrates the execution of commands and subcommands. It handles argument parsing, help generation, and error reporting.
Artisanal's runner is fully integrated with the Style system, providing beautiful, readable help output by default.
Defining Commands
Commands are the building blocks of your CLI. Each command has a name, description, and an optional set of arguments and subcommands.
Override the run() method to implement the command's logic. You can
access the Console via the console property if the command is run
through an Artisanal runner.
Usage
import 'package:artisanal/args.dart';
class MyCommand extends Command {
@override
String get name => 'hello';
@override
String get description => 'Say hello';
@override
void run() {
print('Hello, world!');
}
}
void main(List<String> args) {
final runner = CommandRunner('my-cli', 'A great CLI');
runner.addCommand(MyCommand());
runner.run(args);
}
The CommandRunner orchestrates the execution of commands and subcommands. It handles argument parsing, help generation, and error reporting.
Artisanal's runner is fully integrated with the Style system, providing beautiful, readable help output by default.
Commands are the building blocks of your CLI. Each command has a name, description, and an optional set of arguments and subcommands.
Override the run() method to implement the command's logic. You can
access the Console via the console property if the command is run
through an Artisanal runner.
Classes
- ArgParser
- A class for taking a list of raw command line arguments and parsing out options and flags from them.
- ArgResults
- The results of parsing a series of command line arguments using ArgParser.parse.
-
Command<
T> Core - Base command class for Artisanal-style CLI commands.
- CommandListingEntry
- An entry in a command listing.
-
CommandRunner<
T> Core -
An Artisanal-inspired wrapper around
package:argsCommandRunner.
Functions
-
formatCommandListing(
Iterable< CommandListingEntry> entries, {required String namespaceSeparator, String styleNamespace(String text)?, String styleCommand(String text)?}) → String - Formats a list of commands for display, grouping by namespace.
-
indentBlock(
String input, int spaces) → String -
Indents each line of
inputbyspacesspaces.
Exceptions / Errors
- ArgParserException
-
An exception thrown by
ArgParser.