asika32764 / php-simple-console Goto Github PK
View Code? Open in Web Editor NEWSingle file CLI framework to help you write build scripts.
Home Page: https://packagist.org/packages/asika/simple-console
Single file CLI framework to help you write build scripts.
Home Page: https://packagist.org/packages/asika/simple-console
See: https://forum.friendi.ca/display/ec054ce7255abe539d63ace362184392
Further test revealed that when a CLI script is called with a fully-formed URL as the last argument, $_SERVER['argv']
won't pick it up while $argv
does.
script.php
#!/usr/bin/env php
<?php
var_dump($_SERVER['argv']);
var_dump($argv);
$> php script.php test http://example.com
Output:
array (
0 => 'script.php',
1 => 'test ',
)
array (
0 => 'script.php',
1 => 'test ',
2 => 'http://example.com'
)
The Console::parseArgv
gets passed $_SERVER['argv']
by default, so the Console wouldn't pick on on the argument as well. Here's the workaround I used:
#!/usr/bin/env php
<?php
require_once 'vendor/autoload.php';
// (new \Asika\SimpleConsole\Console())->execute();
(new \Asika\SimpleConsole\Console($argv))->execute();
I'm not sure if and how it can be fixed but for anyone else wondering the workaround might be useful.
Hi there,
A small question. Looking at the Friendica source I see they are using your Console.php code. There is however one spot in the Console.php file where a count is being used instead of calculating the array with a predefined var.
The old code:
protected function parseArgv($argv)
{
$this->executable = array_shift($argv);
$key = null;
$out = array();
for ($i = 0, $j = count($argv); $i < $j; $i++) {
This is a bit faster
protected function parseArgv($argv)
{
$this->executable = array_shift($argv);
$key = null;
$out = array();
$num_argv = count($argv);
for ($i = 0, $j = $num_argv; $i < $j; $i++) {
Would you be willing to change this in the project code so we can use a new version of it? It prevents calling the count function for each iteration.
Thanks,
Hans
Hi and thanks for this gem of a library that I started using over at https://github.com/friendica/friendica. While it does mostly a good job parsing the command-line separating arguments and options, the order is often critical to get the intended result.
For example with an example bin/console
:
bin/console command -p
Arguments:
Options:
But if the order is reversed the result is completely different:
bin/console -p command
Arguments: none
Options:
I'd like to suggest to ignore values for single-letter options and add the possibility to declare specific options that actually expect a value.
What do you think about it?
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.