Skip to content

A gem that allows you to patch the Thor gem bug that displays subcommand help incorrectly

License

Notifications You must be signed in to change notification settings

gangelo/thor_nested_subcommand

Repository files navigation

Ruby GitHub version Gem Version Documentation Report Issues License

ThorNestedSubcommand

ThorNestedSubcommand is a Ruby gem that provides a workaround for the Thor gem 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.

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:

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:

$ 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:

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.

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.

License

The gem is available as open source under the terms of the MIT License.

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.

About

A gem that allows you to patch the Thor gem bug that displays subcommand help incorrectly

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published