phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 431 forks source link

Pass CLI args/options directly into grumphp #874

Closed cnizzardini closed 3 years ago

cnizzardini commented 3 years ago
Q A
Version 1.3
Bug? no
New feature? yes
Question? no
Documentation? no

It would be nice if we could pass CLI switch and arguments directly into grumphp setup. It would make it easy for new users to migrate setups like this to grumphp instead of having to learn the YAML config:

    "scripts": {
        "test": "phpunit --colors=always",
        "phpcs":  "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP plugins/*/src",
        "phpcbf": "phpcbf --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP plugins/*/src",
        "phpstan": "phpstan analyse plugins/*/src",
        "phpmd": "phpmd plugins --exclude tests,assets,config ansi phpmd.xml",

Example:

grumphp:
    tasks:
      phpcs:
          arg: "--colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP plugins/*/src"
veewee commented 3 years ago

I am not sure this will be benificial, since you will need to try X times before getting the command right in combination with the already present options. I'dd say using the documented options is the way to go for this project.

If you want to work with cli options you could also use the shell task: https://github.com/phpro/grumphp/blob/master/doc/tasks/shell.md

Or use the composer task in combination with following package to make it run in parallel as well: https://github.com/veewee/composer-run-parallel

cnizzardini commented 3 years ago

Thanks @veewee

If we are just running shells tasks like that, what am I gaining from using grumphp instead of my own pre-commit git hooks? Aside from a cool logo?

veewee commented 3 years ago

If you want to run everything as if it were a shell command, there aren't many options here. I'dd say the gain is in the config. It might look scary at first, but it all is pretty well documented.

You'll be able to reuse or share task configrations, run things in parallel, make advanced setups with exotic file structures, vagrant + docker support, extendability, and extendable configrations,...

cnizzardini commented 3 years ago

I still think the CLI args makes sense, but you are the maintainer, I'll go with what you say. Thanks.

Edit: Maybe I will submit a PR. I looked through the code and it should be easy enough to modify. I would view the args options as taking precedence over the existing YAML settings which do not always seem to work as I'd expect.