/nette:nette-command-linefrom nette
Helps write and review PHP CLI scripts using nette/command-line 2.0. Covers Command, Parser, ParseResult, HelpRenderer, Console with colors and progress, and migration from 1.x.
Ships in nette. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
composer require nette/command-line
Version 2.0, PHP 8.2 to 8.5, no dependencies. Four classes, each doing one thing: Command describes what the script accepts, Parser reads a command line against it, HelpRenderer draws the help from it, Console writes to the terminal.
Code written for 1.x does not run on 2.0, and some of it fails silently (new Parser($help) drops its arguments). To upgrade, follow the upgrade guide step by step.
use Nette\CommandLine\Command;
use Nette\CommandLine\Console;
use Nette\CommandLine\HelpRenderer;
use Nette\CommandLine\Normalizers;
use Nette\CommandLine\ParseException;
use Nette\CommandLine\Parser;
$command = new Command('convert', 'Converts files between formats.');
$command->addFlag('--help', 'Print this help', alias: '-h', standalone: true);
$command->addFlag('--verbose', 'Verbose output', alias: '-v');
$command->addOption('--output', 'Output file', alias: '-o', valueName: 'file');
$command->addOption('--jobs', 'Parallel jobs', normalizer: Normalizers::int(min: 1), default: 4);
$command->addArgument('input', 'File to convert');
$args = (new Parser)->parse($command); // $_SERVER['argv'], or pass the tokens without the script name
add*() is the description; everything else is named. addOption('--output', '-o') makes -o the description, not the alias.default, an argument after a repeatable one) throw InvalidArgumentException at once.addFlag() takes neither enum nor normalizer; those belong to options and arguments.parse() returns a read-only ParseResult read like an array, keyed by the names as defined, dashes included: $args['--output'], $args['input']. A name that was never defined throws InvalidArgumentException, so a typo does not pass as a missing value; isset() is false for both an unknown name and null. Anything needing a real array (count(), array_*(), json_encode(), a parameter typed array) needs $args->toArray().
| Definition | Absent | Given bare | Given with a value |
|---|---|---|---|
| flag | null | true | refused |
negatable: true, default: true | true | true, --no-x gives false | refused |
| option | null or default | throws, value required | the string |
valueOptional: true | null or default | true | only as --x=value |
| argument | throws unless optional: true | – | the string |
=. --format xml is the option without a value followed by the argument xml – or, in a program with commands, Unknown command 'xml'. With enum: [...] the next token is taken when it is one of the allowed values.default is what the parameter is worth when absent and is returned as given, never normalized nor checked against enum.enum: Format::class (a backed enum) parses straight into the case.repeatable: true collects an array, [] when absent. Without it the last value wins.wasProvided('--x') tells a value equal to the default from the default itself; isEmpty() means nothing followed the script name.Normalizers::int(), float(), realPath(), or any closure) runs only on values from the line. Its exception reaches you as a ParseException naming the parameter.A standalone: true flag answers on its own: the parser returns it as true, the other flags as given and every other parameter at its default, checking or converting nothing and without requiring a missing argument or command. An unknown option is still refused.
$cli = new Command('tool');
$cli->addFlag('--help', alias: '-h', standalone: true);
$check = $cli->addCommand('check', 'Report violations');
$check->addArgument('paths', optional: true, repeatable: true);
$result = (new Parser)->parse($cli);
if ($result['--help']) {
(new HelpRenderer)->render($result->command); // the help of the command the user asked about
exit(0);
}
exit(match ($result->command) {
$check => $app->check($result['paths']),
$cli => $app->usage(),
});
$result->command is the Command object selected by the first positional word, the program itself when there is none (new Command(..., commandRequired: true) refuses that). A command accepts its own options and those of the commands above it. match without a default arm throws when a command is left unhandled.
try {
$result = (new Parser)->parse($cli);
} catch (ParseException $e) {
$stderr = new Console(STDERR);
$stderr->writeLine("Error: {$e->getMessage()}", 'red');
(new HelpRenderer($stderr))->render($e->command);
exit(2);
}
$e->reason is a ParseFailure case (UnknownOption, MissingArgument, ...), $e->parameter the parameter concerned and $e->token the part of the line as given. The help is generated from the definition; addSection() and addText() add headings and paragraphs, hidden: true, valueName: and defaultDescription: shape it. renderToString() returns it, new HelpRenderer(width: 100) fixes the width.
$console->color('red', $text): the color comes first. An unknown color name throws even with colors off; null means no color. Colors are 'fg' or 'fg/bg' from black, gray, silver, white, navy, blue, green, lime, teal, aqua, maroon, red, purple, fuchsia, olive, yellow, drawn in the colors of the terminal theme; a color independent of the theme is '#87D7FF', '#8DF' or a palette number such as '117'.new Console(STDOUT) and new Console(STDERR) decide colors each for itself. How many is a ColorDepth (None, Ansi16, Ansi256, TrueColor), detected from the stream, NO_COLOR, FORCE_COLOR and COLORTERM; new Console(STDOUT, colorDepth: ColorDepth::None) or setColorDepth(ColorDepth::None) (a --no-color option) wins over all of them. There is no useColors().hasColors(), and progress bars or prompts on isTerminal() – colors may be off at a real terminal.$console->link($url, $text) makes a clickable link; in a pipe or without colors the URL follows the text in parentheses.setStatus($lines) draws one line or a list of them in place; the next output erases them and the next setStatus() redraws them below; clearStatus() at the end. It does nothing when the stream is not a terminal.Ansi::measure(), Ansi::pad(), Ansi::truncate($s, $width, keepEnd: true), never strlen(); Ansi::strip() removes foreign escape sequences.The full Nette documentation for this topic is bundled with the plugin. Read a page when you need details beyond this skill:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub nette/agent-plugins --plugin nette20 skills in this plugin
/frontend-developmentProvides frontend development guidelines for Nette. Use when working with Vite, SCSS, JavaScript/TypeScript, Nette Assets ({asset} tag, asset mapping), ESLint with @nette/eslint-plugin, Naja AJAX library, frontend entry points, npm packages in Nette context, Tailwind CSS with Latte templates, nette-forms npm package, HMR, build commands (npm run dev/build), or passing data from PHP to JavaScript./latte-templatesInvoke before creating or modifying .latte files, even for single-line changes. Provides Latte syntax, tags, filters, n:attributes, layouts, template inheritance, AJAX snippets, extensions, and Nette integration. Also trigger when user mentions Latte by name./neon-formatOther plugins' skills for the same job