一键导入
dart-build-cli-app
Entrypoint structure, exit codes, cross-platform scripts. Use when building command line utilities, scripts, or applications.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Entrypoint structure, exit codes, cross-platform scripts. Use when building command line utilities, scripts, or applications.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Guidelines and format for writing pull request descriptions in this repository. Use this skill whenever the user asks you to draft a pull request description, submit a PR, or update a PR description.
Validates an in-progress PR or feature branch of dart_skills_lint against known downstream ecosystem consumers. Use when assessing breaking changes across external repositories during PR evaluation, testing migrations against the changelog, or determining necessary backwards compatibility shims.
How to integrate, update, and configure the dart_skills_lint validation tool within a repository. Make sure to use this skill whenever the user asks to update dart_skills_lint, configure skills validation tests, fix skills linter dependency drifts, verify repository state before editing, optimize lint rules execution, or draft pull request submission commands.
Use this skill when you need to validate AI agent skills with dart_skills_lint — running the linter, interpreting failures, fixing violations, and authoring custom rules.
A deliberately broken fixture used by example/README.md to show what each rule's error output looks like.
Reference fixture for dart_skills_lint. Demonstrates a SKILL.md that passes every default rule: hyphen-lowercase name matching the parent directory, a properly sized description, and no other frontmatter fields that would trigger the disallowed-field check.
| name | dart-build-cli-app |
| description | Entrypoint structure, exit codes, cross-platform scripts. Use when building command line utilities, scripts, or applications. |
| metadata | {"model":"models/gemini-3.1-pro-preview","last_modified":"Fri, 04 May 2026 17:41:00 GMT"} |
Initialize new CLI projects using the official Dart template to ensure standard directory structures.
dart create -t cli <project_name> to scaffold a console application with basic argument parsing.main()) exclusively in the bin/ directory.lib/src/ and expose public APIs via lib/<project_name>.dart.dart format . --set-exit-if-changed. This returns exit code 1 if formatting violations exist.Import the args package to manage command-line arguments, flags, and subcommands.
ArgParser directly to define flags (addFlag) and options (addOption).git): Implement CommandRunner and extend Command for each subcommand.CommandRunner.argParser and command-specific arguments on the individual Command.argParser.UsageException to gracefully handle invalid arguments and display the automatically generated help text.Leverage the io and stack_trace packages to build robust, production-ready CLI tools.
io package's ExitCode enum to return standard POSIX exit codes (e.g., ExitCode.success.code, ExitCode.usage.code).sharedStdIn from the io package if multiple asynchronous listeners need sequential access to standard input.Chain.capture() from the stack_trace package to track asynchronous stack chains.Trace.terse or Chain.terse to strip noisy core library frames and present readable errors to the user.stderr and appropriate non-zero exit codes (e.g., using exit(1) or triggering a 64 exit code after a caught UsageException).[!IMPORTANT] All new commands and significant features must be covered by automated tests. Manual verification is not sufficient for testing logic. However, manual verification of help text and user experience (UX) is still required to ensure the interface is intuitive and correct.
Use test_process and test_descriptor to write high-fidelity integration tests for your CLI.
test_descriptor (d.dir, d.file).await d.Descriptor.create().TestProcess.start('dart', ['run', 'bin/cli.dart', ...args]).StreamQueue matchers (e.g., emitsThrough, emits).await process.shouldExit(0).await d.Descriptor.validate().Select the appropriate compilation target based on your distribution requirements.
dart run bin/cli.dart. This uses the JIT compiler for rapid iteration.dart build cli. This runs build hooks and outputs to build/cli/_/bundle/.dart compile exe bin/cli.dart -o <output_path>. This bundles the Dart runtime and machine code into a single file.dart compile aot-snapshot bin/cli.dart. Run the resulting .aot file using dartaotruntime.Dart supports cross-compiling to Linux from macOS, Windows, or Linux hosts.
Use the --target-os and --target-arch flags with dart compile exe or dart compile aot-snapshot.
--target-os=linux (Only Linux is currently supported as a cross-compilation target)--target-arch=arm64 (64-bit ARM)--target-arch=x64 (x86-64)--target-arch=arm (32-bit ARM)--target-arch=riscv64 (64-bit RISC-V)Example: dart compile exe --target-os=linux --target-arch=arm64 bin/cli.dart
Command in lib/src/commands/.name and description properties.argParser.addFlag() or argParser.addOption().run() method with the core logic.CommandRunner instance in bin/cli.dart using addCommand().test/ directory using test_process or standard tests.dart run bin/cli.dart help <command_name> to verify help text generation.dart compile exe and run the resulting executable to verify the target user experience (e.g., ./bin/cli <command>).dart format . --set-exit-if-changed to ensure code formatting.dart analyze to ensure no static analysis errors.dart test to pass all integration tests.dart compile exe bin/cli.dart -o build/cli-hostdart compile exe --target-os=linux --target-arch=x64 bin/cli.dart -o build/cli-linux-x64import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:stack_trace/stack_trace.dart';
class CommitCommand extends Command {
@override
final String name = 'commit';
@override
final String description = 'Record changes to the repository.';
CommitCommand() {
argParser.addFlag('all', abbr: 'a', help: 'Commit all changed files.');
}
@override
Future<void> run() async {
final commitAll = argResults?['all'] as bool? ?? false;
print('Committing... (All: $commitAll)');
}
}
void main(List<String> args) {
Chain.capture(() async {
final runner = CommandRunner('dgit', 'Distributed version control.')
..addCommand(CommitCommand());
await runner.run(args);
}, onError: (error, chain) {
if (error is UsageException) {
stderr.writeln(error.message);
stderr.writeln(error.usage);
exit(64); // ExitCode.usage.code
} else {
stderr.writeln('Fatal error: $error');
stderr.writeln(chain.terse);
exit(1);
}
});
}
import 'package:test/test.dart';
import 'package:test_process/test_process.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
void main() {
test('CLI formats output correctly and modifies filesystem', () async {
// 1. Setup mock filesystem
await d.dir('project', [
d.file('config.json', '{"key": "value"}')
]).create();
// 2. Spawn the CLI process
final process = await TestProcess.start(
'dart',
['run', 'bin/cli.dart', 'process', '--path', '${d.sandbox}/project']
);
// 3. Validate stdout stream
await expectLater(process.stdout, emitsThrough('Processing complete.'));
// 4. Validate exit code
await process.shouldExit(0);
// 5. Validate filesystem mutations
await d.dir('project', [
d.file('config.json', '{"key": "value"}'),
d.file('output.log', 'Success')
]).validate();
});
}