Redocly / redocly-cli

⚒️ Redocly CLI makes OpenAPI easy. Lint/validate to any standard, generate beautiful docs, and more.
https://redocly.com/docs/cli/
MIT License
849 stars 129 forks source link

Document behaviour of lint cli args after `--` #1581

Closed collinsauve closed 2 weeks ago

collinsauve commented 3 weeks ago

Is your feature request related to a problem? Please describe.

We use pre-commit to automatically hook up a number of linters to our repository.

This tool sends the files that are to be commited as extra command-line arguments to redocly. By way of example, I use a pre-commit config like this:

      - id: my-api lint
        name: my-api lint
        entry:
          pnpm --package=@redocly/cli@1.14.0 dlx redocly lint my-api --config .redocly/config.yaml
        files: ^path\/to\/spec\/.*$
        language: system

Unfortunately due to the above pre-commit behaviour of sending the changed files, the actual command will be sent like this:

pnpm --package=@redocly/cli@1.14.0 dlx redocly lint my-api --config .redocly/config.yaml path/to/spec/file-that-i-changed.yml

Redocly interprets that last argument as a config file.

I found a work-around wherein if I add a -- to the end of the command, Redocly lint ignores anything after it!

Describe the solution you'd like

Pretty simply: Can you confirm that is indeed the expected and supported behaviour, or am I doing some spacebar heating? If it is supported, can it be called out in the docs?

Describe alternatives you've considered

Possibly could wrap it in my own shell script that throws away args.

Additional context

If the above is not clear, I'd be happy to provide a minimum reproduction by way of a small example repository.

tatomyr commented 2 weeks ago

Hi @collinsauve! The behaviour is not specific to Redocly CLI, it's how yargs (which is used as the arguments processor here) handles the input. I'm not sure we need to document that though, since the behaviour is pretty common.

collinsauve commented 2 weeks ago

Thanks for the confirmation that this is expected behavior. My primary concern was that I was relying on something unsupported.

Unfortunately I also don't see this in yargs docs. I used this only because, as you say it is a common pattern. Not going to push too hard on getting it documented now that it is confirmed here.

Thank you!

lornajane commented 2 weeks ago

Thanks @collinsauve I think your usage is the right way to use the -- command. I'm going to close this issue since it's both familiar and also from an upstream repository, so I don't think there's further action for us to take.