infinitered / gluegun

A delightful toolkit for building TypeScript-powered command-line apps.
MIT License
2.95k stars 147 forks source link

Form doesn't return result when skip property is used #720

Closed adriancmiranda closed 3 years ago

adriancmiranda commented 4 years ago

Hey, guys! I'm trying to make a form with a skip option, but the result is always an empty object when I use this property. I'm not sure about this issue should be opened here or at enquirer repo.

{
  type: 'form',
  name: 'bugs',
  choices: [
    { name: 'url', message: 'url', initial: '' },
    { name: 'email', message: 'email', initial: '' },
  ],
  skip() {
    return true;
  },
  message() {
    return 'bugs';
  },
}

returns

{}

should returns

{ url: '', email: '' }

I'm using OSX 10.15.3, node v10.16.2 and npm 6.14.5

jamonholmgren commented 4 years ago

@adriancmiranda Any way you can dig into this and see why it's happening? The relevant code is here:

https://github.com/infinitered/gluegun/blob/f5d7bdb1aef0e082a2fbccdfb7a14bc5cf7a4f1e/src/toolbox/prompt-tools.ts#L34-L51

adriancmiranda commented 3 years ago

Oh, tks @jamonholmgren!

Gluegun is fine! I was testing the enquirer:

const { Form } = require('enquirer');

const prompt = new Form({
    name: 'bugs',
    choices: [
        { name: 'url', message: 'url', initial: '' },
        { name: 'email', message: 'email', initial: '' },
    ],
    skip() {
        return true;
    },
    message() {
        return 'bugs';
    },
});

prompt.run()
    .then(value => console.log('Answer:', value))
    .catch(console.error);

I'm getting the same result. I'm closing this issue here. Tks again! 👍🏼