Coder Social home page Coder Social logo

php-cli-tools's Introduction

PHP Command Line Tools

A collection of functions and classes to assist with command line development.

Requirements

  • PHP >= 5.6

Suggested PHP extensions

  • mbstring - Used for calculating string widths.

Function List

  • cli\out($msg, ...)
  • cli\out_padded($msg, ...)
  • cli\err($msg, ...)
  • cli\line($msg = '', ...)
  • cli\input()
  • cli\prompt($question, $default = false, $marker = ':')
  • cli\choose($question, $choices = 'yn', $default = 'n')
  • cli\menu($items, $default = false, $title = 'Choose an Item')

Progress Indicators

  • cli\notify\Dots($msg, $dots = 3, $interval = 100)
  • cli\notify\Spinner($msg, $interval = 100)
  • cli\progress\Bar($msg, $total, $interval = 100)

Tabular Display

  • cli\Table::__construct(array $headers = null, array $rows = null)
  • cli\Table::setHeaders(array $headers)
  • cli\Table::setRows(array $rows)
  • cli\Table::setRenderer(cli\table\Renderer $renderer)
  • cli\Table::addRow(array $row)
  • cli\Table::sort($column)
  • cli\Table::display()

The display function will detect if output is piped and, if it is, render a tab delimited table instead of the ASCII table rendered for visual display.

You can also explicitly set the renderer used by calling cli\Table::setRenderer() and giving it an instance of one of the concrete cli\table\Renderer classes.

Tree Display

  • cli\Tree::__construct()
  • cli\Tree::setData(array $data)
  • cli\Tree::setRenderer(cli\tree\Renderer $renderer)
  • cli\Tree::render()
  • cli\Tree::display()

Argument Parser

Argument parsing uses a simple framework for taking a list of command line arguments, usually straight from $_SERVER['argv'], and parses the input against a set of defined rules.

Check examples/arguments.php for an example.

Usage

See examples/ directory for examples.

Todo

  • Expand this README
  • Add doc blocks to rest of code

php-cli-tools's People

Contributors

aerogus avatar barbushin avatar danielbachhuber avatar dllh avatar gitlost avatar igorsantos07 avatar jesseoverright avatar jlogsdon avatar kodie avatar leewillis77 avatar lf-jeremy avatar lucasvanlierop avatar luxian avatar marcovalloni avatar markjaquith avatar miya0001 avatar nochso avatar nyholm avatar pfefferle avatar rodrigoprimo avatar schlessera avatar scribu avatar slaffik avatar swissspidy avatar thanj avatar tiagohillebrandt avatar tollmanz avatar urlund avatar valeriyseregin avatar zipofar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-cli-tools's Issues

Use HTML-like syntax instead of own custom one

What I mean is to replace:

%ySomething yellow%n

with:

<y>Something yellow</y>

Benefits:

  • easier and more familiar to read, since there is no ySomething and similar things, at the end of the day we are all well trained to read HTML:)
  • IDE usually supports HTML within string literals, so it will be:
    • automatically highlighted
    • possible to fold blocks of text
    • working with autocomplete of closing such "tags"
    • working with spellchecking
    • so on...
  • there are numerous HTML parsers that can be used to pre/post-process such strings or strip HTML tags from string

I've implemented such approach in very basic form here: https://github.com/nazar-pc/phpt-tests-runner/blob/master/bin/phpt-tests-runner#L284
Even GitHub is capable to automatically highlight it in a basic form 😄

Paging arguments for `cli\Table`

It would be nice if cli\Table could display current page and total page values in some way, if there were multiple pages of values. A bonus would be to interactively walk through the pages.

`wp post get $id` returns no `post_title` when the content contains English, Japanese, and Thai language characters

Here's the post_content I have in the editor.

♫ มีอีกหลายต่อหลายคน เขาอดทนก็เพื่อรัก
รักผลักดันให้รู้จัก ให้หาหนทางใหม่
ฉันจะล้มตั้งหลายที ดีที่รักมาฉุดไว้
รักสร้างสรรค์สิ่งมากมาย และหลอมละลายทุกหัวใจ
จะมาร้ายดียังไง แต่ใจก็ยังต้องการ
ในทุกๆ วัน โลกหมุนด้วยความรัก ♫
ขอแสดงความยินดี งานแต่งพี่ Earn & Menn
-----
...เที่ยวปายหน้าร้อน ก็เที่ยวได้เหมือนกันน่ะ

ジョバンニはまっ赤になってうなずきました。けれどもいつかジョバンニの眼のなかには涙がいっぱいになりました。そうだ僕は知っていたのだ、もちろんカムパネルラも知っている。

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore

And I attache the output in my terminal.

2017-08-02 12 08 48

% characters not properly escaped before being passed to sprintf()

Using WP CLI, the following steps show the problem:

  • Update your user account so that your name contains a %, e.g. "Lee %s Willis"
  • Run wp user list
  • Expected output:
+----+-------------+---------------+---------------------+---------------------+---------------+
| ID | user_login  | display_name  | user_email          | user_registered     | roles         |
+----+-------------+---------------+---------------------+---------------------+---------------+
| 5  | leewillis77 | Lee %s Willis | [email protected] | 2015-07-19 15:11:01 | subscriber    |
  • Actual output
+----+-------------+---------------+---------------------+---------------------+---------------+
| ID | user_login  | display_name  | user_email          | user_registered     | roles         |
+----+-------------+---------------+---------------------+---------------------+---------------+
| 5  | leewillis77 | Lee  Willis | [email protected] | 2015-07-19 15:11:01 | subscriber    |
  • Note that the name of the user is displayed as "Lee Willis".

The %s has not been escaped and has been passed to sprintf as-is. There is code already in place that looks like it tries to handle this, but it doesn't.

PR to follow that simplifies the escaping (and resolves this issue), obviously it'll need review to see why the original wasn't this straightforward.

% characters not properly escaped before being passed to sprintf

Using WP CLI, the following steps show the problem:

  1. Update your user account so that your name contains a %, e.g. "Lee %s Willis"
  2. Run wp user list
  3. Note that the name of the user is displayed as "Lee Willis".

The %s has not been escaped and has been passed to sprintf as-is.

The repository is corrupted

This repository is one of few which are corrupted by the bug introduced some years ago (around 2009) at GitHub (see the following thread for more information).

The corruption manifests itself if transfer.fsckObjects is set to true in git config files and/or when you run git fsck on the cloned repository:

git fetch wp-cli/php-cli-tools master
warning: no common commits
remote: Counting objects: 814, done.
remote: Compressing objects: 100% (330/330), done.
error: object ce411870d883dc16cb58988797a9059d3ab25e54:contains zero-padded file modes
fatal: Error in object
fatal: index-pack failed

I'm not sure how to fix it correctly since nobody provided an easy solution on the net so far. As far as I know the recommended solution would be to do git fast-export followed by git fast-import since it will re-create the structure correctly.

Allow the Streams::render() function to recieve a `$colorize` parameter

I'm not sure if I'm missing something obvious or not... please let me know if this is already being handled.

I'm trying to work out how to pass an additional argument in my calls to \cli\line, \cli/out, and the related functions that will be passed on to Colors::colorize() as the second parameter. Specifically, I'm trying to use the is_atty() conditional to determine whether or not to output colorized output.

As far as I can tell, any additional arguments get thrown away in the Streams::render() function, rather than being passed on to Colors::colorize(); so I can't figure out how to make that happen.

Does this make sense? Do you have a workaround in place?

Prompting doesn't support arrow keys

From: wp-cli/wp-cli#996

Prompting doesn't support arrow keys because php-cli-tools uses fgets(STDIN) instead of readline:

https://github.com/wp-cli/php-cli-tools/blob/master/lib/cli/Streams.php#L130

The following seem to fix this issue:

diff --git a/lib/cli/Streams.php b/lib/cli/Streams.php
index b750636..081a6bd 100755
--- a/lib/cli/Streams.php
+++ b/lib/cli/Streams.php
@@ -126,6 +126,8 @@ class Streams {

                if( $format ) {
                        fscanf( static::$in, $format . "\n", $line );
+               } else if ( function_exists( 'readline' ) ) {
+                       $line = readline();
                } else {
                        $line = fgets( static::$in );
                }

But, at least for wp-cli --prompt parameter, another problem is created. If you use the left arrow to go to the beginning of what you typed, the cursor goes to the beginning of the line, before the question presented to the user. I think this happens because readline() expects the question as a parameter. So we will need to change that as well.

exec unable to fork and excessive querying of terminal columns

Every time Shell::columns is called it runs exec to retrieve the number of terminal columns. This however can cause issues depending on the system configuration leading to "unable to fork" errors, and null values being returned.

This in turn leads to negative values being passed to strrepeat in the Bar progress class, and erroneous output.

This version of the columns method handles the erroneous output by falling back to 80, but still generates a warning on calling exec regarding failure to fork :

    static public function columns() {
        if ( stripos( PHP_OS, 'indows' ) === false ) {
            $columns = exec('/usr/bin/env tput cols');
            if ( is_numeric( $columns ) ) {
                return $columns;
            }
        }
        return 80; // default width of cmd window on Windows OS, maybe force using MODE CON COLS=XXX?
    }

I would suggest calling exec once and saving the value, preventing the issue and reducing the number of exec calls to 1.

ASCII renderer does not work with the given example

Had to rewrite that renderer to make it work. Like so:

public function render(array $tree, $cycle=0)
{
    $output = '';

    foreach ($tree as $key => $value) {
        if (is_array($value)) {
            $output .= $this->displayDepth($cycle) . $key . "\n";
            $output .= $this->render($value, $cycle+1);
        } else {
            $output .= $this->displayDepth($cycle) . $value . "\n";
        }
    }

    return $output;
}

private function displayDepth($cycle)
{
    if ($cycle == 0) {
        return '/';
    } else {
        $a   = 0;
        $out = '';
        while ($a < $cycle) {
            $out .= '  ';
            $a++;
        }

        return $out . '/';
    }
}

Piping data and prompting

Is there a way to read piped data as an input and also use the prompt feature?
I can't seem to find a way around this Error:
ERROR: exception 'Exception' with message 'Caught ^D during input' in .../wp-cli/php-cli-tools/lib/cli/Streams.php:139

I tried using the input() function to read the piped data, or to do it manually, it doesn't change anything, I can't manage to create a prompt in the second cli php script.

I'm new to build cli apps that read piped data, so it could be a generality in PHP or I just haven't found any solution yet...

Any help will be greatly appreciated!
Thanks

Colors::length returns incorrect lengths for colorized strings

When you pass a string to Colors::length that has already been colorized with Colors::colorized, the wrong result is given. This issue resulted in incorrectly formatted tables using \cli\Table::display().

To reproduce:

  1. Add the following WP CLI command:

    <?php
    
    class ReducedTestCase extends WP_CLI_Command {
      function test() {
          $success = \cli\Colors::colorize( "%Gx%n" );
    
          // Display results
          $table = new \cli\Table();
          $table->setHeaders( array( 'Test Header' ) );
          $table->setRows( array( array( $success )) );
          $table->display();
      }
    }
    
    WP_CLI::add_command( 'failwhale', 'ReducedTestCase' );
  2. The output produced is:

    vagrant@vvv:/srv/www/wordpress-develop/src$ wp failwhale test
    +--------------+
    | Test Header  |
    +--------------+
    | x |
    +--------------+

    Note that the output is colorized even though I cannot indicate that in the code above.

  3. The expected output is:

    vagrant@vvv:/srv/www/wordpress-develop/src$ wp failwhale test
    +--------------+
    | Test Header  |
    +--------------+
    | x            |
    +--------------+

This problem is occurring because before the content is passed to the table methods, it is colorized. Colorizing the string turns it from:

%Gx%n to something like \033[32;1mx\033[0m

The string length counts are thusly messed up. In fact, I'd argue that the string lengths, for any version of colorized values have always been messed up. The first value above would return a length of 5 and the second a value of 18 when really, the string length should be 1 as the only non-color value is x.

I was able to implement a really sloppy proof of concept fix for the issue:

static public function length($string) {
    // Convert the string back to it's original state
    $conversions = array(
        '%y' => array('color' => 'yellow'),
        '%g' => array('color' => 'green'),
        '%b' => array('color' => 'blue'),
        '%r' => array('color' => 'red'),
        '%p' => array('color' => 'magenta'),
        '%m' => array('color' => 'magenta'),
        '%c' => array('color' => 'cyan'),
        '%w' => array('color' => 'grey'),
        '%k' => array('color' => 'black'),
        '%n' => array('color' => 'reset'),
        '%Y' => array('color' => 'yellow', 'style' => 'bright'),
        '%G' => array('color' => 'green', 'style' => 'bright'),
        '%B' => array('color' => 'blue', 'style' => 'bright'),
        '%R' => array('color' => 'red', 'style' => 'bright'),
        '%P' => array('color' => 'magenta', 'style' => 'bright'),
        '%M' => array('color' => 'magenta', 'style' => 'bright'),
        '%C' => array('color' => 'cyan', 'style' => 'bright'),
        '%W' => array('color' => 'grey', 'style' => 'bright'),
        '%K' => array('color' => 'black', 'style' => 'bright'),
        '%N' => array('color' => 'reset', 'style' => 'bright'),
        '%3' => array('background' => 'yellow'),
        '%2' => array('background' => 'green'),
        '%4' => array('background' => 'blue'),
        '%1' => array('background' => 'red'),
        '%5' => array('background' => 'magenta'),
        '%6' => array('background' => 'cyan'),
        '%7' => array('background' => 'grey'),
        '%0' => array('background' => 'black'),
        '%F' => array('style' => 'blink'),
        '%U' => array('style' => 'underline'),
        '%8' => array('style' => 'inverse'),
        '%9' => array('style' => 'bright'),
        '%_' => array('style' => 'bright')
    );

    foreach ($conversions as $key => $value) {
        $string = str_replace(self::color($value), '', self::colorize($string, true));
    }

    return safe_strlen(self::colorize($string, true));
}

As a proof of concept, this simply converts the colorized string to the original string without any color information. This gets the true string length value. Furthermore, this gives the expected results in the table display. This is a sloppy fix and it produced noticeable performance issues.

I think there are a lot of different approaches to fixing this issue. An approach that I think could work would be too:

  1. Whenever a new value is passed to Colors::colorize, store that value in memory and specifically track:
    • String without any color information
    • The original string value
    • The colorized value
  2. Change the Colors::length method to do a simple strlen call on the string without any color information.

I think this method would be backwards compatible, and provide a nice performance boost by removing redundant color conversions.

Additionally, I think some unit testing should be added to show how broken these methods are.

Retain ascii table formatting when shell is Piped

I'm using php-cli-tools with wp-cli. When I call wp from an external program like Vim's system function, it detects that stdout is a pipe, and omits formatting and colors.

I would like it to retain the formatting regardless of whether the Shell is piped or not. One solution I came up with is to pass a SHELL_PIPE environment variable. If it's present then isPiped method will use it instead of doing tty detection.

Another option is to remove the conditional from \cli\Table and respect what display mode was requested of it.

I made the PR against the downstream wpcli tools fork. I can make the PR against this repo if there is interest in the ENV implementation. The wp-cli discussion on this issue is here.

Thanks.

Composer autoload broken

I'm new to composer so forgive me if I'm just using it incorrectly.

I added your project to my composer.json like so:

{
    "require": {
        "jlogsdon/cli": "0.9.*"
    }
}

However I got errors like this:

PHP Fatal error:  Call to undefined function cli\line() in ~/dev/myproject/vendor/jlogsdon/cli/lib/cli/Table.php on line 115

The solution was for me to modify my composer.json to add cli.php:

{
    "require": {
        "jlogsdon/cli": "0.9.*"
    },
    "autoload": {
        "files": ["vendor/jlogsdon/cli/lib/cli/cli.php"]
    }
}

Since there aren't any classes in that file (and your composer.json is set to psr-0) I don't think it is finding the functions correctly.

I think the fix to this could be as simple as modifying your composer.json to look something like this:

{
    "autoload": {
        "psr-0": {"cli": "lib/"},
        "files": ["lib/cli/cli.php"]
    }
}

Missing releases

Please, create new releases for the project so we can properly update our dependent projects without having to rely on dev-master (:

Colors in table

Hi,

I know you havent touched this for some time, but its aweome!
Just one question/request, how do I combine colors with the table? Id like colored text in the table.
It does work, but extra characters for the color coding mess up the table layout.
Thanks!

\cli\progress\Bar enhancement: Allow updating _message on tick

Inspired by the progress bar as implemented by the league/climate package, it'd be useful to allow updating the _message property displayed by a progress bar as it is working on different items being processed or hits different key steps of processing.

In their progress bar documentation, the updated message is passed as an optional second parameter of their equivalent tick method.

Using a similar method signature, this would not be a breaking change and would give the option for better visibility of work/steps/tasks being performed. I'm going to extend the \cli\progress\Bar class in the meantime, but it seems like it'd be useful in general use cases for anyone to use.

Colors::colorize removes sprintf flags on windows

I'm using the script on windows, and shouldColorize returns false, so the following lines strips all sprintf flags:

$return = preg_replace('/%((%)|.)/', '$2', $string);

Causes cli\menu() to show a list of dots instead of the choices.

The warning throw by _parseOption($option) in the Arguments class is inconsistent

Using the "arguments" example, I found out that php arguments.php -n -v provided the following output:

Warning: [cli\Arguments] no value given for -n in /your/path/...../vendor/wp-cli/php-cli-tools/lib/cli/Arguments.php on line 412
{"name":null,"verbose":true}

which is anticipated, but that one php arguments.php -n produced:

[]

So, no warning although there was no value passed in for the "-n" option either.

I've a quick fix for that. I'll shoot a PR.

Note
That also illustrates the "default" bug.
php arguments.php -n should produce:

{"name":"James","verbose":true}

since "James" is set as default. But there is already an issue open for that one.

Incorrect require's in Arguments.php

Hi,

In my copy of the code, installed via composer, the require lines in the Arguments.php file were incorrect.

To get them to work I needed to change them to:

require 'Memoize.php';
require 'arguments/Argument.php';
require 'arguments/HelpScreen.php';
require 'arguments/InvalidArguments.php';
require 'arguments/Lexer.php';

The returned value of `--format=count` needs line break?

There is no line break. Is this problem which should be fixed?
Are there any backward compatibility issues?

[miya@localhost wp-cli (master *)]$ wp user list --format=count
1[miya@localhost wp-cli (master *)]$ 

For example, the result of the jq has a line break.

$ wp user list --format=json | jq length
1

Request: argument defaults and types

It would be helpful if arguments had a type assigned to them.

  • int - numeric
  • path - automatically resolved based on CWD
  • string - default

Also it would be helpful if you could give arguments a default value or otherwise mark them as optional.

v0.9.4 removed from packagist?

My Travis builds errored this morning because it couldn't find v0.9.4 when running composer update --prefer-source. I may be misreading something, but it looks like v0.9.4 is no longer available on the php-cli-tools Packagist page. Any ideas?

Here is the error from Travis:

$ composer update --prefer-source
Loading composer repositories with package information�
Updating dependencies (including require-dev)�
Your requirements could not be resolved to an installable set of packages.�

  Problem 1
    - The requested package wp-cli/php-cli-tools could not be found in any version, there may be a typo in the package name.
  Problem 2
    - Installation request for jeremykendall/slim-auth dev-develop -> satisfiable by jeremykendall/slim-auth[dev-develop].
    - jeremykendall/slim-auth dev-develop requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
  Problem 3
    - jeremykendall/password-validator dev-master requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator dev-feature/coveralls requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator dev-dead-feature/phpass-implementation requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator 2.0.2-beta requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator 2.0.1-beta requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator 2.0.0-beta requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator 1.1.0-beta requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator 1.0.0-beta requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - jeremykendall/password-validator dev-develop requires wp-cli/php-cli-tools v0.9.4 -> no matching package found.
    - Installation request for jeremykendall/password-validator @dev -> satisfiable by jeremykendall/password-validator[1.0.0-beta, 1.1.0-beta, 2.0.0-beta, 2.0.1-beta, 2.0.2-beta, dev-dead-feature/phpass-implementation, dev-develop, dev-feature/coveralls, dev-master].

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

The command "composer update --prefer-source" failed and exited with 2 during before_script.

Your build has been stopped.

Here is a copy of my composer.json:

{
    "name": "jeremykendall/flaming-archer",
    "description": "A photo 365 project application. Requires user to have a Flickr API key",
    "license": "MIT",
    "authors": [
        {
            "name": "Jeremy Kendall",
            "homepage": "http://about.me/jeremykendall",
            "role": "Developer"
        }
    ],
    "keywords": [
        "photography",
        "flickr",
        "photo-a-day",
        "photo 365"
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "http://packages.zendframework.com/"
        }
    ],
    "require": {
        "php": ">=5.4",
        "ext-mcrypt": "*",
        "doctrine/common": "~2.4",
        "guzzle/guzzle": "~3.8",
        "ircmaxell/password-compat": "1.*",
        "jeremykendall/slim-auth": "dev-develop",
        "jeremykendall/password-validator": "@dev",
        "monolog/monolog": "1.*",
        "pimple/pimple": "v1.0.2",
        "slim/slim": "~2.4",
        "slim/views": "0.1.*",
        "symfony/event-dispatcher": "2.3.*",
        "twig/twig": "1.13.*",
        "wp-cli/php-cli-tools": "v0.9.4",
        "zendframework/zend-authentication": "2.2.*",
        "zendframework/zend-cache": "2.2.*",
        "zendframework/zend-config": "2.2.*",
        "zendframework/zend-feed": "2.2.*",
        "zendframework/zend-inputfilter": "2.2.*",
        "zendframework/zend-paginator": "2.2.*",
        "zendframework/zend-serializer": "2.2.*",
        "zendframework/zend-session": "2.2.*"
    },
    "require-dev": {
        "composer/composer": "1.0.*@dev",
        "mikey179/vfsStream": "1.2.*",
        "mockery/mockery": "0.8.0",
        "jeremykendall/phpctagger": "dev-master",
        "phpunit/phpunit": "3.7.*",
        "whatthejeff/nyancat-phpunit-resultprinter": "v1.2.0"
    },
    "autoload": {
        "psr-0": {
            "FA": "src/"
        }
    },
    "scripts": {
        "post-install-cmd": [
            "FA\\Composer\\Script\\SQLite::prepare"
        ],
        "post-update-cmd": [
            "rm -rf templates/cache/*"
        ]
    }
}

Menu is not working

Running examples/menup.php provide the following output instead of the requested menu:
%d. %s
%d. %s
%d. %s
%d. %s
%d. %s
%d. %s

Choose an example:

Default value for Options not returned

Setting a default for an option doesn't really seem to do much (besides showing the default value in the help screen:

$arguments->addOption( array('name', 'n'), 
    array(
        'description' => 'Set the name",
        'default' => 'Foo Bar'
    )
));

Doing this:

echo $arguments['name']

returns nothing, but it should return "Foo Bar" unless the default has been overridden.

E_NOTICE

PHP Notice: Undefined offset: 0 in /php-cli-tools/lib/cli/cli.php on line 99

This (and a few others) were introduced in commit dcd7551

using readline() for the autocomplete callback?

Hi...

I'd like to see autocomplete options (specifically for file paths).

It appears you can do this with readline, and setting a readline callback function.

This can probably be an almost drop-in replacement for the standard prompt (the one that uses fgets()), but it might not work with the one that uses fscanf().

James

Cron, posix_isatty and STDOUT

when running under cron and automating some task, my log keeps on throwing in:

production.ERROR: exception 'ErrorException' with message 'Use of undefined constant STDOUT - assumed 'STDOUT'' in /var/www/seat-ec/vendor/wp-cli/php-cli-tools/lib/cli/Shell.php:57

I've been looking for several day's to get this fixed or getting a satisfied solution but the results are null to not helping. Perhaps you might be able to help me solving this issue.

CentOS 6.5, Easyapache with php 5.4
STDOUT is a TTY output to what's told.

sprintf(): Too few arguments

Can't really figure this one out. Sometimes (not often, but often enough to end up in my logs and irritate me) \cli\line() causes a warning: sprintf(): Too few arguments.

This is the offending line:

\cli\line("[%C%k%s%N] Starting!", date("Y-m-d H:i:s"));

Can't really see how the argument to sprintf() gets lost here, but obv it does.

environment: php5.6.33 (with mbstring) on debian, php-cli-tools v0.11.8.

Logfile trace:

in function LoggingErrorHandler::handleError
in function call_user_func in /foo/include/classes/LoggingErrorHandler.php on line 402
in function LoggingErrorHandler::{closure}
in function sprintf
in function call_user_func_array in /foo/include/deps/wp-cli/php-cli-tools/lib/cli/Streams.php on line 48
in function cli\Streams::render
in function call_user_func_array in /foo/include/deps/wp-cli/php-cli-tools/lib/cli/Streams.php on line 13
in function cli\Streams::_call in /foo/include/deps/wp-cli/php-cli-tools/lib/cli/Streams.php on line 68
in function cli\Streams::out
in function call_user_func_array in /foo/include/deps/wp-cli/php-cli-tools/lib/cli/Streams.php on line 13
in function cli\Streams::_call in /foo/include/deps/wp-cli/php-cli-tools/lib/cli/Streams.php on line 95
in function cli\Streams::line
in function call_user_func_array in /foo/include/deps/wp-cli/php-cli-tools/lib/cli/Streams.php on line 13
in function cli\Streams::_call in /foo/include/deps/wp-cli/php-cli-tools/lib/cli/cli.php on line 62
in function cli\line in /foo/bin/my_foobar_script.php on line 35

Missing $pad_type in Colors::pad() (str_pad)

Trying to align numbers to the right in a cli table, but STR_PAD_LEFT seems to be missing.

Current ASCII table creates:

+----+------+---------+
| ID | Name | Balance |
+----+------+---------+
| 3  | Foo  | 10,00   |
| 10 | Bar  | 1200,00 |
+----+------+---------+
|    |      | 1210,00 |
+----+------+---------+

What I want is:

+----+------+---------+
| ID | Name | Balance |
+----+------+---------+
|  3 | Foo  |   10,00 |
| 10 | Bar  | 1200,00 |
+----+------+---------+
|    |      | 1210,00 |
+----+------+---------+

But Colors::pad() while extending ACSII table padColum does not have the possibility to provide STR_PAD_RIGHT or STR_PAD_LEFT based on the $column number.

Fixed in PR: #120

UTF-8 compatibility

Since master/lib/cli/Streams.php is using sprintf, library may fail on multi-byte character set.

Progress bar goes to new line under windows

The progressbar instead of updating the current row print a new row with the updated values.

To fix this I've found that can be esily fixed by changing into Bar.php line 58 from

$size = Shell::columns();

to

$size = Shell::columns() - 1;

If it was ok as I fix I can also make a pull request for it.

Currently I've not tested it under others OS.

Percent characters cause issues with sprintf

When having a percent character in your content (at least with a table) causes sprintf errors since this expects this to be a placeholder. Percent characters should therefore be escaped

Add command line parser

Hi,

Your tools are very usefull, but PHP misses a simple but powerful CLI command line parser.

Ideally it should support :

  • Both long and short options
  • Sub commands

Thanks !

require failed to open stream

try to access examples/

all files return error.

require(lib/cli/cli.php) failed to open stream: No such file or directory in examples\common.php on line 12

PHP 5.3

What requirement i need to install more than just PHP 5.3?

Function use error

Arguments.php
string 87
code
public function offsetExists($offset) {
if ($offset instanceOf \cli\arguments\Argument) {
$offset = $offset->key;
}
return array_key_exists($offset,$this->_parsed); << fixed
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.