Coder Social home page Coder Social logo

pharse's People

Contributors

chrisallenlane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

oyang wolxxx

pharse's Issues

Create a unit test

Test:

  • Long option parsing
  • Long options with hyphenated names (see #3)
  • Short option parsing
  • Type constraints
  • Default values

PHPUnit could be overkill, so I might just try to hack something together using assert() statements. This doesn't need to be complicated.

Allow options with no shortcut

I have an application that should show help and a -h[ost] option. However, I think it's pointless to have a shortcut for --help, and would like to disable it, but if I try to put the argument as false, the library creates the shortcut as "-" simple, and null creates a default one.

Default is not set when option is not given

How does the default option works?

I've set an option with a default, and required: false; however, if the user does not specify that option, I don't get anything by default too... It works, though, if the user specify the option without a value.
There's nothing about this in the example either. Could you give a valid example?

Bugs

I tested the code so that we can start using it in our projects. For this I've forked the code and try to make it match our corporate standards. I guess the new code is very different from the original ideas here and it would be really hard to pull changes back. But I can put the list of issues I have found.

'0' value for the parameter is considered empty and not allowed

For example

ubuntu@soft-rose:/home/test/pharse$ ./example.php --username 0
Error: required value for --username was not specified.

The check 0 == null is true in PHP and this is why '0' parameter value is considered empty.

if ($this->required && $this->value == null) {

String parameter can not have numeric value

For example

ubuntu@soft-rose:/home/test/pharse$ ./example.php --username 123
Error: option --username must be a string.

Parameter type is not checked for non required parameters

To test this you need to change example file

    'username' => array(
        'description'   => 'Your username',
        'default'       => 'admin',
        'type'          => Pharse::PHARSE_INTEGER,
        'required'      => false,
        'short'         => 'u',
    ),

Then when you invoke it like this no error is shown

ubuntu@soft-rose:/home/test/pharse$ ./example.php --username abc --password abc
Only root is allowed to log in. Disconnect immediately or we will do literally nothing about it.

PHP unit tests

I have to admit I don't know how would you write PHP unit tests because of all these die() statements in the code. I can understand that this is part of the concept but it makes testing very complicated. Also the code with static methods and properties is hard to test too.

Hope this might be helpful.

Thank you for your time. And wish you happy coding ;)

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.