hongaar / bandersnatch

➰ Simple and intuitive yet powerful and versatile framework for Node.js CLI programs
https://github.com/hongaar/bandersnatch/blob/main/README.md
MIT License
47 stars 6 forks source link

Feature Request: Subcommands and Nesting #626

Closed khill-fbmc closed 2 weeks ago

khill-fbmc commented 3 months ago

First off, love this library, primarily for the REPL features. I keep eyeing Clipanion since it seems like it is designed to be used as a multi-command, nested type of program. I like that, but then I loose my nice REPL features you've added.

This is what I have setup so far, (match is from ts-pattern)

image

It works, but does not feel very scalable. Is there a better approach to make nested type commands?

hongaar commented 2 months ago

Nested command can be added like this:

program()
  .add(
    command("session")
      .add(
        command("start")
          .action(() => console.log("start"))
      )
      .add(
        command("stop")
          .action(() => console.log("stop"))
      )
      // and so on...
  )
  .run();

Hope this helps.

If you have any ideas how to improve this for your use case, I'm curious to hear!