You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get a list of all commands, subcommands and options of a class that inherits from Thor. For example, the module CLI below inherits from Thor and has two commands actor and service as shown below:
actor.rb
module CLI
module Commands
class Actor < CLI::Commands
desc "monitor <AppName>", "Monitor the current app"
def monitor(app_name)
# do something
end
desc "new <AppName>", "New App"
def new(app_name)
# do something
end
end
end
service.rb
module CLI
module Commands
class Service < CLI::Commands
desc "deploy <SERVICE_NAME>", "Deploy service"
def deploy(name)
# do something
end
end
end
I'm looking for a command list_commands that could list all commands and their methods and subcommands in a JSON like format
Currently, kind of get what I what by putting help in front of each command/subcommand to get the next subcommand. My intention to use the output of the above command is to auto-generate a bash-completion script as new commands are added into the Commands module that inherits from CLI which inherits from Thor. Suggestions for any other approaches using some inbuilt mechanism in Thor are also welcome!
I took a slightly different approach to auto complete using complete -C /path/to/command command where instead of a script generated, bash calls the command directly to ask what should be used.
I'm trying to get a list of all commands, subcommands and options of a class that inherits from Thor. For example, the module CLI below inherits from Thor and has two commands actor and service as shown below:
actor.rb
service.rb
I'm looking for a command
list_commands
that could list all commands and their methods and subcommands in a JSON like formatCurrently, kind of get what I what by putting
help
in front of each command/subcommand to get the next subcommand. My intention to use the output of the above command is to auto-generate a bash-completion script as new commands are added into theCommands
module that inherits fromCLI
which inherits fromThor
. Suggestions for any other approaches using some inbuilt mechanism in Thor are also welcome!PS: Also take a look at a similar SO question
The text was updated successfully, but these errors were encountered: