Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to read filename or '-' #91

Open
OnkelTem opened this issue Jul 11, 2018 · 3 comments
Open

Impossible to read filename or '-' #91

OnkelTem opened this issue Jul 11, 2018 · 3 comments

Comments

@OnkelTem
Copy link

OnkelTem commented Jul 11, 2018

It's very common for a file processing script to either take the filename OR '-' to get data from stdin.
With this library I cannot do this:

php convert.php input.log
php convert.php - < input.log

Whenever I pass "-" it says

ERROR: Unable to parse option -: Invalid syntax

My definition was like:

  $cmd->option()
    ->require()
    ->describedAs('Input log file or `-` to read from stdin');

and value reading part was as simple as:

  $filename = $cmd[0];
@NeoVance
Copy link
Contributor

At the moment our parser can not handle - without a short option following it. The majority of bash commands handle stdin input without the need for the dash at the end of the command so it has not been a priority to implement.

In any case; reading data from stdin is beyond the scope of this library, being a command line argument parser, and is left for the user to implement.

You can use needs and/or map to handle arguments that are required to be supplied or optionally piped in through stdin.

@OnkelTem
Copy link
Author

OnkelTem commented Jul 11, 2018

The majority of bash commands handle stdin input without the need for the dash at the end of the command...

I'm not sure about what do you exactly mean under 'bash commands', but that's of course not true for the majority of standard set of *nix programs (e.g.: tar). Any detection magic is more a flaw than a feature. Programs shouldn't make any assumptions about their environment unless they're told explicitly what to do.
And detecting stdin/stdout on PHP particularly - is a well know kind of perversion, yeah :)

You can use needs and/or map to handle arguments that are required to be supplied or optionally piped in through stdin.

Thanks, I'll take a look. Another workaround I used - I tweaked $_SERVER['argv}'] taking my positional argument out of there.

@NeoVance
Copy link
Contributor

@OnkelTem Initializing Command($tokens) with a modified token list can be useful! That is usually how I do my sub-commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants