This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
JBZoo/Cli is a PHP library that extends Symfony Console functionality for creating CLI applications. It provides enhanced progress bars, strict type conversion for options, styling, multiple output modes, profiling, and multiprocessing capabilities.
make test-all- Run all project tests including codestyle checksmake test- Run PHPUnit testsmake codestyle- Run code style checks on src/make codestyle PATH_SRC=./demo- Run code style checks on demo/phpunit- Run unit tests directly (uses phpunit.xml.dist)
make update- Install/update all 3rd party dependencies via Composercomposer update- Update Composer dependencies
phpstan- Run PHPStan static analysis (uses phpstan.neon config)
make test-logstash- Run Logstash manual tests and output to build/logstash.log
-
CliApplication- Main application class that extends Symfony Application- Registers commands by directory path scanning
- Manages output modes and event handling
- Located in
src/CliApplication.php
-
CliCommand- Base class for all CLI commands that extends Symfony Command- Provides enhanced option parsing with strict types (
getOptInt,getOptBool,getOptString, etc.) - Built-in progress bar functionality via
progressBar()method - Output method aliases (
$this->_()instead of$output->writeln()) - Located in
src/CliCommand.php
- Provides enhanced option parsing with strict types (
-
CliCommandMultiProc- Extension for multiprocessing commands- Implements
executeOneProcess()andgetListOfChildIds()methods - Located in
src/CliCommandMultiProc.php
- Implements
Three output modes in src/OutputMods/:
Text- Default user-friendly outputCron- Timestamped logs for crontab (combines--timestamp --profile --stdout-only --no-progress -vv --no-ansi)Logstash- JSON format for ELK Stack integration
Enhanced progress bar system in src/ProgressBars/:
ProgressBar- Main progress bar implementationProgressBarLight- Lightweight versionProgressBarSymfony- Symfony-compatible wrapperProgressBarProcessManager- For multiprocessing scenarios
CliHelper- Helper functions and utilitiesCliRender- Rendering utilities for lists and formattingCodes- Exit code constantsOutLvl- Output verbosity level constantsIcons- Icon constants for CLI output
Commands should extend CliCommand and implement executeAction() method. Use the demo commands in demo/Commands/ as examples:
DemoSimple.php- Basic command structureDemoProgressBar.php- Progress bar usageDemoOutput.php- Output and verbosity examplesDemoOptionsStrictTypes.php- Strict type option parsing
Commands are auto-discovered by CliApplication::registerCommandsByPath() which scans directories for PHP files extending CliCommand.
Use strict type methods instead of raw option values:
$this->getOptInt('option-name')instead of$this->getOption('option-name')$this->getOptBool(),$this->getOptString(),$this->getOptArray(),$this->getOptDatetime()
- Use
$this->_($message, $verboseLevel, $context)for output - Use global
cli($message, $verboseLevel, $context)function outside command classes - Use
$this->progressBar()for loops with progress tracking
src/- Main library codedemo/- Example CLI application showing library featurestests/- PHPUnit testsvendor/- Composer dependencies
JBZoo\Cli\maps tosrc/JBZoo\PHPUnit\maps totests/(dev)