tj / commander.js

node.js command-line interfaces made easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

return command action result

baravak opened this issue · comments

I want to use this library in Net Socket connections, and I need to send the output of each action as a socket response. Is there a solution for this?

  const serverSignal = createServer((socket) => {
    socket.on('data', (data) => {
      const result = await Program.parseAsync()
      socket.write(result)
      socket.end()
    })
  })

For capturing the Commander output, have a look at the README section covering .configureOutput() and .exitOverride().

send the output of each action

To clarify, do you mean your own text output to stdout or stderr from the action handler, or some value the action handler returns? There isn't support in Commander for capturing either, and up to you!

Related issues with some ideas: #1666 #1776

An answer was provided, and no further activity in a month. Closing this as resolved.

Feel free to open a new issue if it comes up again, with new information and renewed interest.