bombshell-dev / clack

Effortlessly build beautiful command-line apps
https://clack.cc
5.23k stars 88 forks source link

[Bug] group #188

Closed FedeRBeije closed 5 months ago

FedeRBeije commented 5 months ago

Environment

Describe the bug

  1. When i try to use group from @clack/prompts i get undefined as results
  2. If i just await group(... it print all in ones and i can't choose the values and does some strange glitch shows the outro but then it will removed it(video)
  3. The var that should have the values from group is undefined. Also in the video
  4. The onCancel method is not working. If i ctrl + c the program ends but not in the right way(video 2)

To Reproduce

Just create a group with select and multiselect

Steps to reproduce the behavior:

const templateGroup = await group(
      {
        language: async () => {
          await select({
            message: 'Select a language',
            options: [
              {label: 'Typescript', value: 'typescript'},
              {label: 'Javascript', value: 'javascript'},
            ],
            initialValue: 'typescript',
          })
        },
        config: async () => {
          await multiselect({
            message: 'Select the config you want to use',
            options: [
              {value: 'tailwind', label: 'Tailwind'},
              {value: 'tanstackQuery', label: 'Tanstack Query', hint: 'recommended'},
              {value: 'zustand', label: 'Zustand', hint: 'recommended'},
              {value: 'redux', label: 'Redux'},
            ],
            initialValues: ['tailwind', 'tanstackQuery', 'zustand'],
            required: true,
          })
        },
      },
      {
        onCancel: () => {
          console.log('Operation cancelled')
          cancel('Operation cancelled')
          process.exit(0)
        },
      },
    )
 outro(`You selected ${templateGroup.language} and ${JSON.stringify(templateGroup.config)} for your project!`)

Expected behavior I should get the values

Additional Information

image

https://github.com/natemoo-re/clack/assets/108535310/9fd97ffc-bbba-4f20-82ea-9c4fa9d3a2d7

https://github.com/natemoo-re/clack/assets/108535310/f9f102d7-c34f-4b76-aef7-33cae1a477c7

Mist3rBru commented 5 months ago

Hello @FedeRBeije!

For the group to work, you need to return the prompt result at each call.

For example:

const templateGroup = await group(
      {
        language: async () => {
-         await select({
+         return await select({
            message: 'Select a language',
            options: [
              {label: 'Typescript', value: 'typescript'},
              {label: 'Javascript', value: 'javascript'},
            ],
            initialValue: 'typescript',
          })
        },
FedeRBeije commented 5 months ago

Oh i see, my mistake sorry. Thanks

Mist3rBru commented 5 months ago

No problem! If you have any further questions or concerns, feel free to ask. 🚀