https://github.com/gangelo/thor_nested_subcommand
A gem that allows you to patch the Thor gem bug that displays subcommand help incorrectly
https://github.com/gangelo/thor_nested_subcommand
Last synced: about 1 year ago
JSON representation
A gem that allows you to patch the Thor gem bug that displays subcommand help incorrectly
- Host: GitHub
- URL: https://github.com/gangelo/thor_nested_subcommand
- Owner: gangelo
- License: mit
- Created: 2022-10-06T20:14:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T18:37:24.000Z (over 1 year ago)
- Last Synced: 2025-04-11T04:35:46.821Z (about 1 year ago)
- Language: Ruby
- Size: 37.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://github.com/gangelo/thor_nested_subcommand/actions/workflows/ruby.yml)
[](https://badge.fury.io/gh/gangelo%2Fthor_nested_subcommand)
[](https://badge.fury.io/rb/thor_nested_subcommand)
[](http://www.rubydoc.info/gems/thor_nested_subcommand/)
[](http://www.rubydoc.info/gems/thor_nested_subcommand/)
[](https://github.com/gangelo/thor_nested_subcommand/issues)
[](#license)
# ThorNestedSubcommand
`ThorNestedSubcommand` is a Ruby gem that provides a workaround for the [Thor gem](https://rubygems.org/gems/thor) bug that displays nested subcommand help incorrectly. Simply include the `ThorNestedSubcommand` module in your Thor nested subcommand, and provide a simple class method to return what Thor help shoul be displaying, and that's it.
## Usage
First, follow instructions for [installation](#installation).
Secondly, do the following in your Thor `subcommand`:
* include the `ThorNestedSubcommand`.
* Add a `.base_name` class method and return the base name for the nested `subcommand` you need Thor help to display.
For example:
```ruby
require 'thor'
require 'thor_nested_subcommand'
class Command < ::Thor
desc 'sub_command SUBCOMMAND', 'sub command'
subcommand :sub_command, SubCommand
end
class SubCommand < ::Thor
desc 'nested_sub_command SUBCOMMAND', 'nested sub command'
subcommand :nested_sub_command, NestedSubCommand
end
# Thor help breaks because this is a nested subcommand.
class NestedSubCommand < ::Thor
# Include this:
include ThorNestedSubcommand
class << self
# Add this:
def base_usage
# Return what Thor shoud be displaying for your nested subcommand:
'sub_command nested_sub_command'
end
end
desc 'test', 'test the command'
def test
puts 'test'
end
end
```
That's it. Disaster averted:
```shell
$ command sub_command help nested_sub_command
> Commands:
> command sub_command nested_sub_command help [COMMAND] # Describe subcommands or one specific subcommand
> command sub_command nested_sub_command test # test sub sub command
```
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'thor_nested_subcommand'
```
And then execute:
$ bundle install
Or install it yourself as:
$ gem install thor_nested_subcommand
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/thor_nested_subcommand. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/thor_nested_subcommand/blob/main/CODE_OF_CONDUCT.md).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the ThorNestedSubcommand project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/thor_nested_subcommand/blob/main/CODE_OF_CONDUCT.md).