Git Product home page Git Product logo

yargs-interactive's Issues

Following your example adding --interactive doesn't allow interactive mode

^ like what title says.

I'm trying to enter interactive mode, but whatever I do, i can't. Am I missing something here?

i saved the file like so in test.js


const yargsInteractive = require("yargs-interactive");
const options = {
  interactive: { default: true },
  name: { type: "input", default: "A robot", describe: "Enter your name" },
  likesPizza: {
    type: "confirm",
    default: false,
    describe: "Do you like pizza?",
  },
};

yargsInteractive()
  .usage("$0 <command> [args]")
  .interactive(options)
  .then((result) => {
    // Your business logic goes here.
    // Get the arguments from the result
    // e.g. myCli(result.name);
    console.log(
      `\nResult is:\n` +
        `- Name: ${result.name}\n` +
        `- Likes pizza: ${result.likesPizza}\n`
    );
  });

then i run

node test.js --interactive

outputs immediately without prompts:


Result is:
- Name: A robot
- Likes pizza: false

How do you use it with commands?

I don't see how to use this package with commands. E.g. ...

yargsInteractive()
    .command('do-it', 'Does things.', o => o
      .options(myOptions))
    .strict()
    .demandCommand()
    .help()
    .argv;

I can only call .interactive(...) and pass in options directly from the yargsInteractive() return. I can't seem to configure an interactive command.

How to use the list type from inquirer?

Do list types work for this? I'm playing around and trying the following as an option

  Favorite: {
    describe: "What is your favorite color?",
    prompt: "always",
    type: "list",
    choices: [
      "Blue",
      "Red",
      "Green",
      "Yellow",
      "Orange"
    ],
  },

But I just get an error saying You must provide a choices parameter.

Support for Typescript typings

@nanovazquez I don't know how familiar you are with Typescript, but I opened a PR at DefinitelyTyped to have typings for yargs-interactive. I need to update it now that options is choices. But I'm thinking the interfaces should probably extend from inquirer at some point. I'm just not sure what all is passed from yargs-interactive to inquirer here. Any input on that PR would be helpful.

Checkbox list doesn't work on Linux

I just implemented this code with a single param of type checkbox and it works perfectly fine on my Windows machine (using Git Bash with powerline), but on my Linux hosting machine (Shell: zsh v5.4.2 / bash v4.4.20 | Distro: Ubuntu 18.04.3 LTS) it completely breaks. Linux at the top.

image

And this is the list I'm feeding the checkbox command as choices:
image

The sourecode is on GitHub: https://github.com/Favna/ribbon/
Or the specific commit which adds the file where I use yargs interactive: favna/ribbon@fcaa7f8

Supplying argument does not remove prompt in `if-empty` mode

Steps to replicate

  1. Create 'mixed mode' example as described within README.md
  2. Invoke with --name='Johh' --interactive args (also shown in README)

Expected behaviour

I will not be prompted for name, as it has been supplied as an arg

Actual behaviour

I am prompted for name

Potential fix

I think I've fixed the problem locally with these changes:

--- a/node_modules/yargs-interactive/src/yargs-interactive.js
+++ b/node_modules/yargs-interactive/src/yargs-interactive.js
@@ -29,10 +29,15 @@ let yargsInteractive = (processArgs = process.argv.slice(2), cwd) => {
 
     // Remove options with prompt value set to 'never'
     // and options with prompt value set to 'if-empty' but no default value or value set via parameter
-    const interactiveOptions = filterObject(mergedOptions, (item, key) => (
-      item.prompt !== 'never'
-      && (item.prompt !== 'if-empty' || isEmpty(item.default) || isEmpty(argv[key]))
-    ));
+    const interactiveOptions = filterObject(mergedOptions, (item, key) => {
+      if (item.prompt === 'never') {
+        return false;
+      }
+      if (item.prompt === 'always') {
+        return true;
+      }
+      return isEmpty(item.default) && isEmpty(argv[key]);
+    });
 
     // Check if we should get the values from the interactive mode
     return argv.interactive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.