vanilla / garden-cli Goto Github PK
View Code? Open in Web Editor NEWA full-featured, yet ridiculously simple commandline parser for your next php cli script. Stop fighting with getopt().
License: MIT License
A full-featured, yet ridiculously simple commandline parser for your next php cli script. Stop fighting with getopt().
License: MIT License
An extra (public) function showHelp()
which triggers writeHelp()
(with its proper arguments) would be nice to have.
It seems to me that, while there is code to check for options being required and not being provided, the same thing does not happen for arguments.
I have an example with a cli command requiring 3 arguments and an optional fourth. If I don't provide any argument, the program doesn't stop. Am i doing something wrong?
cli.php --string-option
should set string-option
to (empty string)
and not "1"
if the option is not required.
The LogFormatter right now is hardcoded to php://output. I want to be able to specify another output stream or even multiple output destinations, some of which may not be a file stream (ex. database, syslog). The garden-cli won't be responsible for doing any of the work or wiring these up; it just needs to make useful classes available to libraries.
Any changes must be backwards compatible.
I've been trying the library on windows and that doesn't support the bold or colored items you have in there by default. It would be great if there was a way to turn that off without having to fiddle with the libraries code.
Key syntax choices
Important warnings
Naming conventions
Convention for React Component with props/state interfaces.
Include getting starting links.
Running garden-cli with PHP 8.1.5 gives me:
Deprecated: Return type of Garden\Cli\Schema\OptSchema::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:_pro\Target\target_web\vendor\vanilla\garden-cli\src\Schema\OptSchema.php on line 231
Deprecated: Return type of Garden\Cli\Args::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:_pro\Target\target_web\vendor\vanilla\garden-cli\src\Args.php on line 219
Deprecated: Return type of Garden\Cli\Args::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:_pro\Target\target_web\vendor\vanilla\garden-cli\src\Args.php on line 236
Deprecated: Return type of Garden\Cli\Args::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:_pro\Target\target_web\vendor\vanilla\garden-cli\src\Args.php on line 247
Deprecated: Return type of Garden\Cli\Args::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:_pro\Target\target_web\vendor\vanilla\garden-cli\src\Args.php on line 259
Deprecated: Return type of Garden\Cli\Args::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in D:_pro\Target\target_web\vendor\vanilla\garden-cli\src\Args.php on line 270
I can not push to new branch or create pull request. So... If okay, please help me doing these:
src\Schema\OptSchema.php
Line 231: Add return type: mixed
public function jsonSerialize() : mixed {
src\Args.php
Line 219: Add return type: mixed
public function jsonSerialize() : mixed {
Line 236: Add return type: bool
public function offsetExists($offset) : bool {
Line 247: Add return type: mixed
public function offsetGet($offset) : mixed {
Line 259: Add return type: void
public function offsetSet($offset, $value) : void {
Line 270: Add return type: void
public function offsetUnset($offset) : void {
Doing this will break compatibility with PHP below Version 7. But since the requirement for garden-cli is PHP 7 or above, then i think it's safe to do above changes.
If I enter -?
to get the help for a registered command as suggested, nothing happens.
$ php cli.php auth:token -?
zsh: no matches found: -?
The long help with --help
works like expected.
$ php cli.php auth:token --help
usage: cli.php auth:token [<options>]
Get token for credentials.
OPTIONS
--help, -? Display this help.
--pass, -p The Password.
--user, -u The Username.
It maybe has to do with macOS Monterey 12.6.5 (21G531) with zsh 5.8.1 (x86_64-apple-darwin21.0) installed.
For my personal project, i've built a console system with this awesome tool. But i need to implement the success (green color) message, and change colors of other formatted messages.
How to do this?
This does not work as documented:
$log = new TaskLogger();
$log->info('This is a message.')
->error('This is an error.') // outputs in red
The info()
method has return type void in the trait. It only works like this:
$log = new TaskLogger();
$log->info('This is a message.');
$log->error('This is an error.');
I am trying to run https://github.com/bramus/mixed-content-scan. When I enter the command I get the following error message:
user:/home/www/user > files/swm2/composer/.composer/vendor/bin/mixed-content-scan https://example.com
Content-type: text/html; charset=UTF-8
Fatal error: Uncaught Exception: Garden\Cli\Cli::parseRaw expects an array in /files/swm2/composer/.composer/vendor/bramus/mixed-content-scan/vendor/vanilla/garden-cli/src/Cli.php:385
Stack trace:
#0 /files/swm2/composer/.composer/vendor/bramus/mixed-content-scan/vendor/vanilla/garden-cli/src/Cli.php(338): Garden\Cli\Cli->parseRaw(NULL)
#1 /files/swm2/composer/.composer/vendor/bramus/mixed-content-scan/bin/mixed-content-scan(40): Garden\Cli\Cli->parse(NULL, true)
#2 {main}
thrown in /files/swm2/composer/.composer/vendor/bramus/mixed-content-scan/vendor/vanilla/garden-cli/src/Cli.php on line 385
This error is thrown with both garden-cli version 1.6.3 and 2.0.
Using PHP 7.1.9 (cgi-fcgi).
How to fix this?
There is a way to make a parameter accept multiple arguments?
Example:
$cli->arg( 'SINGLE', ''...,' true ); $cli->arg( 'MULTIPLE', ''...,' true. true // multiple );
Usage:
$ mycopy source target1 target2 target3....
Hi
Why is setting values not permitted? Is there any workaround? Like get a copy of parsed options?
I want to use a "--dry" flag that will automatically activate few other options via boolean flags, so the user doesn't have to type 3 switches but just to use one.
$command= new Commando\Command();
//some optionsare defined here
//--dry flag should enable --skip --run --show flags
if ($command['dry']) {
$command['skip'] = true;
$command['run'] = true;
$command['show'] = true;
}
Fatal error: Uncaught Exception: Setting an option value via array syntax is not permitted in C:\......1
Stack trace:
This is more of a feature request than an actual issue, but still:
Please add an option to allow the equals symol to be used as a seperator for option name and value.
Right now you have no seperator at all or space (and thus a new element in argv) as a separator.
Having the = like the getopt from php does would be very welcome here.
Thanks in advance.
It would be nice if you could ask for the usage / help details programmatically (I.e public methods on the Cli
class for: getUsage()
or getHelp()
/ getHelp($command)
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.