cmd-ts icon indicating copy to clipboard operation
cmd-ts copied to clipboard

How to execute shell commands inside `handler`?

Open nikivdev opened this issue 2 years ago • 5 comments

I tried doing this:

import { command, optional, positional, run, string } from "cmd-ts"
import { execa } from "execa"

const cmd = command({
  name: "gitty",
  description: "automate git",
  version: "0.0.1",
  args: {
    query: positional({ type: optional(string), displayName: "query" }),
  },
  handler: async (args) => {
      const { stdout } = await execa("echo", ["unicorns"])
      console.log(stdout)

  },
})

run(cmd, process.argv.slice(2))

But then if you try run it, you won't get echo unicorns as output.

If you run below code outside the handler:

      const { stdout } = await execa("echo", ["unicorns"])
      console.log(stdout)

It works as expected. Not sure why that happens or how to fix.

nikivdev avatar Mar 02 '23 16:03 nikivdev

repo where I am using cmd-ts: https://github.com/nikitavoloboev/gitty

code I want to make work is here

nikivdev avatar Mar 02 '23 16:03 nikivdev

What’s the console output then?

Schniz avatar Mar 02 '23 20:03 Schniz

It's empty.

image

nikivdev avatar Mar 02 '23 20:03 nikivdev

Very suspicious. I hope I will have some time to take a look. You are more than welcome to fork and add a test.

Schniz avatar Mar 04 '23 21:03 Schniz