dry-rb / dry-cli

General purpose Command Line Interface (CLI) framework for Ruby
https://dry-rb.org/gems/dry-cli
MIT License
327 stars 41 forks source link

Allow adding subcommand toplevel documentation (usage) #96

Open magec opened 4 years ago

magec commented 4 years ago

It would be nice to be able to add documentation to command prefixes. The way dry-cli deals with subcommands disallows adding documentation to be shown calling --help over the subcomand prefix.

Examples

Given the code on this example:

require "dry/cli"

module Foo
  module Commands
    extend Dry::CLI::Registry

    module Generate
      class App < Dry::CLI::Command
      end

      class Action < Dry::CLI::Command
      end
    end

    register "generate", aliases: ["g"] do |prefix|
      prefix.register "app",    Generate::App
      prefix.register "action", Generate::Action
    end
  end
end

It would be nice to be able to add documentation over the 'generate' subcommand. So its help will be shown like:

Description:

here you can include a general documentation about the subcommand.

Commands:
  foo.rb generate action
  foo.rb generate app

A possible implementation could be:

    register "generate", aliases: ["g"] do |prefix|
      prefix.desc 'HERE YOU CAN INCLUDE THE DOCUMENTATION OF THE COMMAND'
      prefix.register "app",    Generate::App
      prefix.register "action", Generate::Action
    end

I checked the code and saw that Prefix class was just syntax sugar for self.register, so no idea on how this could be implemented, or whether there is already a way of achieving what I'm looking for.

Thanks in advance! and thanks for dry-cli!