Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Ability to negate server option #1466

Open
kylef opened this issue Aug 14, 2019 · 5 comments
Open

Ability to negate server option #1466

kylef opened this issue Aug 14, 2019 · 5 comments
Labels
Epic: configuration Command line options, dredd init, dredd.yml

Comments

@kylef
Copy link
Member

kylef commented Aug 14, 2019

When I have a configuration file, such as:

language: nodejs
hookfiles: dredd/*.js
server: env VAULT_ENABLED=0 node functions/transform/lib/http.js
server-wait: 3
color: true
path: []
blueprint: 'apiary.apib'
endpoint: 'http://localhost:8000'

I'd like to be able to override the server, to not run, for example if I am running the script against the already ran server in some kind of debug mode, or docker image etc.

Having an argument such as --no-server which negates the server option would be neat.

Workaround

$ npx dredd --config dredd.local.yml --server '/usr/bin/true'

Although, this suffers from slowing down the tests as there is 3 second wait due to server-wait.

Describe the solution you'd like

I'd like to see --no-server (or something similiar, --no is common pattern for disabling boolean flags in a lot of tools I use so this feels like an intuitive option, although never seen pattern where main argument requires option (i.e, git --no-pager).

Another example:
https://github.com/kylef/swiftenv/blob/2caa152249c02af42360afd737c9b7ae679d2910/libexec/swiftenv-install#L263-L266

@kylef
Copy link
Member Author

kylef commented Aug 14, 2019

I realise the --no- pattern is already used in Dredd to negate options:

  --color                            Use --color/--no-color to enable/disable
                                     colored output              [default: true]

Although, it doesn't appear to apply to other options such as --no-dry-run (perhaps this enhancement is that we should consistently have --no- option for all boolean flags and options that make sense).

  --dry-run, -y                      Do not run any real HTTP transaction, only
                                     parse API description document and compile
                                     transactions.               [default: null]

@honzajavorek
Copy link
Contributor

I can confirm I wanted Dredd to support --no- fully for boolean options, similar to what click does. The --color option has been revisited since, so it has got this, but the others are from old times where there has been no --no-, pretty much.

So yes, this is a wanted feature. I'm surprised I didn't find it mentioned in #1101, but I remember mentioning it to @netmilk as one of the first things when I was introduced to Dredd 🙂

@honzajavorek honzajavorek added the Epic: configuration Command line options, dredd init, dredd.yml label Aug 14, 2019
@artem-zakharchenko
Copy link
Contributor

Can this be solved by using another CLI framework, i.e. yargs?

@artem-zakharchenko
Copy link
Contributor

artem-zakharchenko commented Sep 2, 2019

It also appears that Optimist supports options negation out of the box. Can we apply this for our use case?

After a discussion with @honzajavorek, the reason why the default negation doesn't apply to the server option is because its value is a String, not a Boolean.

@honzajavorek
Copy link
Contributor

Can this be solved by using another CLI framework, i.e. yargs?

Yes, please 🙂 #845

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Epic: configuration Command line options, dredd init, dredd.yml
Projects
None yet
Development

No branches or pull requests

3 participants