Provides a micro-framework for building CLI tools in PHP.
Warning
This project is not finished yet, work in progress.
You can install the package via composer:
composer require ghostwriter/cliYou can also star (🌟) this repo to find it easier later.
<?phpdeclare(strict_types=1);
namespaceVendor\Project;
useGhostWriter\Cli\Attribute\Application;useGhostWriter\Cli\Attribute\Argument;useGhostWriter\Cli\Attribute\Command;useGhostWriter\Cli\Attribute\Option;useGhostwriter\Cli\Core\MiddlewareInterface;
#[Command(name: 'new', description: 'Create a new project')]
finalclass NewCommand
{
#[Argument(help: 'Project name')]
publicstring$name;
#[Option(short: 't', long: 'type', help: 'Project type')]
publicstring$type = 'php';
#[Option(short: 'd', long: 'directory', help: 'Project directory')]
publicstring$directory;
}
#[Command(name: 'help', description: 'Show help')] finalclass HelpCommand
{
#[Argument(help: 'Command to show help for')]
public ?string$command = null;
}
#[Command(name: 'list', description: 'List all projects')]
finalclass ListCommand
{
#[Option(short: 't', long: 'type', help: 'Project type')]
publicstring$type = 'php';
}
finalreadonlyclass GitHubAuthMiddleware implements MiddlewareInterface
{
publicfunction__construct(privatestring$token) {}
#[Override]
publicfunctionprocess(CommandInterface$command, HandlerInterface$handler): ResultInterface
{
$command->env['GITHUB'] = $this->token;
return$handler->handle($command);
}
}
#[Application(
package: 'ghostwriter/architect',
commands: [NewCommand::class, HelpCommand::class, ListCommand::class],
middlewares: [GitHubAuthMiddleware::class]
)]
finalclass Architect
{
// Default options available in all subcommands (help, version)
#[Option(short: 'h', long: 'help', help: 'Show help')]
publicbool$help = false;
#[Option(short: 'v', long: 'version', help: 'Show version')]
publicbool$version = false;
// Custom optional options (with default values)
#[Option(short: 'b', long: 'bool', help: 'Set the boolean flag')]
publicbool$bool = false;
#[Option(short: 'f', long: 'float', help: 'Set the float to <float>')]
publicfloat$float = 0.0;
#[Option(short: 'i', long: 'int', help: 'Set the integer to <int>')]
publicint$int = 0;
#[Option(short: 's', long: 'string', help: 'Set the string to <string>')]
publicstring$string = '#BlackLivesMatter';
#[Option(short: 'l', long: 'list', help: 'Set the list to <list>')]
publicarray$list = [];
#[Option(short: 'n', long: 'null', help: 'Set the null to <null>')]
public ?string$null = null;
// Custom required options
#[Option(short: 'r', long: 'required', help: 'Set the required to <required>', required: true)]
publicstring$required;
// Required arguments
#[Argument(help: 'Project name')]
publicstring$project;
// Optional arguments (with default values)
#[Argument(help: 'Project directory')]
publicstring$directory = '.';
}
$exitCode = \GhostWriter\Cli\Application::new(Architect::class)->run($_SERVER['argv']);
exit($exitCode);Please see CHANGELOG.md for more information on what has changed recently.
Please see LICENSE for more information on the license that applies to this project.
Please see SECURITY.md for more information on security disclosure process.