-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commands registration and commands section #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi Alexandre 👋 Thanks for giving this gem a try. This gem, in terms of scope, is complete. I plan to add more DSL goodies to make it easier to use, for example, to specify conflicting options. However, I don't expect the shape of it to change much. Only to become more polished with time. This means that it will never support commands. Like many of tty components, they are all focused on doing one thing well and being as composable as possible. As for creating CLI applications with commands, I've tried to answer this in the closed issue. Please have a read when you get a moment. Essentially, the commands will be handled by another library. However, as I developed the In the meantime, if you want to support commands, there is a discussion that may help you out. |
I see, so commands are not in the scope of tty-options but that's something for tty-runner. Do you plan to release it someday? Or should I ally tty-options for buildings single commands and dry-cli for managing all commands? Thanks for the pointers.
Yeah, I'm a big user of docopt.rb which is just awesome and magic for simple applications, but it soon begins to be limited when you wan't to build complex application, as, for example, options will conflict between commands etc. For one project with multiple commands I gave a try to dry-cli (which is part of dry-rb that tries to achieve something similar to ttytoolkit) which is very good for building many commands but severely lacks of tons of essential features that are included in tty-options. So if you think tty-runner is not ready maybe using tty-options and dry-cli could complete each other well. |
Of course, but there are a few thorny issues that I first need to figure out like the aforementioned dependencies handling in commands. It will require writing a separate gem to deal with this part of the issue. But please don't wait for
I'm not sure that's possible. As far as I can tell, the
The |
Describe the problem
Having
:commands
section would help a lot.Right now it's a pain for:
Here is what I ended up doing (example for 1 command).
In my binary:
The default root command:
Because I want that when the root pseudo-command (no command) help is triggered, to display a section with all available commands.
But of course I'm not injection any commands section on commands themselves (unless of course the command would have sub commands).
Random example I found from a gem to register several commands:
https://github.com/OfficialPhilcomm/staticz/blob/1eaa3945f48f81138c129e73c303f9bf975f3318/lib/staticz.rb#L9-L25
Then this gem hacks into the description section to inject a pseudo commands section which is 100% static
https://github.com/OfficialPhilcomm/staticz/blob/1eaa3945f48f81138c129e73c303f9bf975f3318/lib/commands/base_command.rb#L11-L17
Of course the most official way to do it right now is using
sections.add_after :description, :commands
but it's static too unless you inject each command name and description.Here another example where one preferred not to use tty-options to craft a default command that will list all available commands while it uses tty-options for all other commands.
https://github.com/smashwilson/branchtree/blob/dc0a24f3841169da224ee2a883b1a9a77b244525/lib/branchtree.rb#L6-L28
How would the new feature work?
I don't know but in the past I use dry-cli that has a way to register commands so there is no need to hack into ARGV.
Example in production, registering commands is as easy as this clean mapping and it will automatically display a commands section.
Here another original very complex way of doing it dynamically
https://github.com/MadBomber/sqa/blob/main/lib/sqa/cli.rb
Seems that every one try to hack very hard around this common issue.
Drawbacks
I don't see any.
The text was updated successfully, but these errors were encountered: