nanovazquez / yargs-interactive

Interactive support for yargs
MIT License
46 stars 9 forks source link

Prompt only for missing args? #8

Closed themightychris closed 6 years ago

themightychris commented 6 years ago

Is there a usage where prompts can be shown only for options not set via command line?

nanovazquez commented 6 years ago

Hi @themightychris! There isn't at the moment, but it's not hard to implement. See here, we are filtering options with prompt set to false. We can add another value to only filter these options if the value is set.

Is that what you are looking for?

themightychris commented 6 years ago

@nanovazquez that sounds about right!

nanovazquez commented 6 years ago

Alright, I think we should change the prompt property to receive 3 values: always, never and if-empty. By default it will be set to if-empty, prompting if the value was not provided either via the command line or the default values.

I've started this branch to release the new version of the library, that will include this (breaking) change. Feel free to continue the implementation, otherwise, I'll add the code during the week.

themightychris commented 6 years ago

If boolean values could be interpreted with something like typeof prompt == 'boolean' ? (prompt ? 'always' : 'never') : prompt then it wouldn't need to be a breaking change, right?

nanovazquez commented 6 years ago

You are right. But should we? As long as we release a new version I don't see the problem of treating it as a breaking change (unless I'm missing something).

nanovazquez commented 6 years ago

We have a candidate in #9. I'll work on the tests and release it as soon as they pass.

nanovazquez commented 6 years ago

There you go, @themightychris. The new prompt option, with the if-empty configuration is now available in v2.0.0. You can use it by simply doing something like this:

const options = {
  name: {
    prompt: 'if-empty';
  }
  ...
};

And then yargs-interactive will prompt the name option if a value was not supplied via default value or command parameters.

themightychris commented 6 years ago

amazing work, thank you @nanovazquez !