unjs / citty

🌆 Elegant CLI Builder
Other
729 stars 23 forks source link

[Question] Process exit dont exit the terminal. #128

Open prpanto opened 5 months ago

prpanto commented 5 months ago

OS: Windows 11 Home latest terminal: Windows Terminal latest citty: version latest node: v20.11.1 electron: v28.2.6

I have an electron app and I try to use citty for some simple commands but when I run the .exe file all works perfect but on in the end the process dont exit. I ask because maybe is my fault. Add process.exit in the run (maybe unnecessary), tell me if is wrong.

Code I use:

const main = defineCommand({
  meta: {
    name: "hello",
    version: "1.0.0",
    description: "My Awesome CLI App",
  },
  args: {
    name: {
      type: "positional",
      description: "Your name",
      required: true,
    },
    friendly: {
      type: "boolean",
      description: "Use friendly greeting",
    },
  },
  run({ args }) {
    console.log(`${args.friendly ? "Hi" : "Greetings"} ${args.name}!`)
    process.exit(0)
  }
})

runMain(main)

Edit: The weird thing... check how the terminal behaves...

C:\{path_to_the_project}>YourAppName.exe hello MyName

C:\{path_to_the_project}>
Greetings MyName!
(now terminal stuck)

(I press `enter` and then normal)
C:\{path_to_the_project}>

What behavior I expect:

C:\{path_to_the_project}>YourAppName.exe hello MyName
Greetings MyName!

C:\{path_to_the_project}>    (no stuck just exit)
peterroe commented 5 months ago

👀 Would you willing to provide a reproduction with https://stackblitz.com ?