Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yargs-interactive

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yargs-interactive - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

src/is-args-provided.js

2

package.json
{
"name": "yargs-interactive",
"version": "2.0.2",
"version": "2.1.0",
"description": "Build interactive command line tools without worring to parse the arguments (or ask them).",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -130,7 +130,7 @@ # Yargs Interactive

| default | any | The default value of the option. |
| prompt | string | _(Default is `if-empty`)_ Property to decide whether to prompt the option or not. Possible values: `always`, `never` and `if-empty`, which prompts the option if the value wasn't set via command line parameters or using the default property. |
| prompt | string | _(Default is `if-empty`)_ Property to decide whether to prompt the option or not. Possible values: `always`, `never`, `if-no-arg` (prompts if the option was not sent via command line parameters) and `if-empty` (prompts if the value was not sent via command line parameters and it doesn't have a default property). |
### Prompt just some questions (mixed mode)
You can opt-out options from interactive mode by setting the `prompt` property to `never`. By default, its value is `if-empty`, prompting the question to the user if the value was not set via command line parameters or it doesn't have a default property. Last, you can use `always` to always prompt the option.
You can opt-out options from interactive mode by setting the `prompt` property to `never`. By default, its value is `if-empty`, prompting the question to the user if the value was not set via command line parameters or it doesn't have a default property. Setting to `if-no-arg` will only prompt the question if no argument is provided. Lastly, you can use `always` to always prompt the option.

@@ -137,0 +137,0 @@ **my-cli.js**

@@ -5,2 +5,3 @@ const yargs = require('yargs');

const isEmpty = require('./is-empty');
const isArgProvided = require('./is-args-provided');

@@ -14,18 +15,12 @@ // Set up yargs options

// Merge options sent by parameters with interactive option
const mergedOptions = Object.assign(
{},
options,
{
interactive: {
default: !!(options.interactive && options.interactive.default),
prompt: 'never',
}
const mergedOptions = Object.assign({}, options, {
interactive: {
default: !!(options.interactive && options.interactive.default),
prompt: 'never'
}
);
});
// Run yargs with interactive option
// and get the requested arguments
const argv = yargsConfig
.options(mergedOptions)
.argv;
const argv = yargsConfig.options(mergedOptions).argv;

@@ -44,2 +39,7 @@ // Filter options to prompt based on the "if-empty" property

// Prompt items that are set with 'if-no-arg' and values were not send via command line parameters
if (item.prompt === 'if-no-arg') {
return !isArgProvided(key, processArgs);
}
// Cases: item.prompt === "if-empty" or item.prompt undefined (fallbacks to "if-empty")

@@ -59,3 +59,2 @@ // Prompt the items that are empty (i.e. a value was not sent via parameter OR doesn't have a default value)

module.exports = yargsInteractive;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc