[proposal] dry-cli


#1

I’m working on a ruby CLI at the moment and I have been using thor:
http://whatisthor.com/

I’ve been toying with this idea for a little while but it seems like the model of dry-types and the coercion/constraints would play nicely into a CLI. To that end, I was wondering if this has been broached before, what status that might be at, and whether it’s something that might be considered in the future.

I feels like a simple interface could be something like (although obviously informal at this point)

class CLI < Dry::CLI
   register_command 'action', Action, desc: 'Some textual description'
  
  class Action
    extend Dry::CLI::Command

    param :arg1, Types::String.enum('opt1', 'opt2'), desc: 'This is the first arg', default: -> { 'opt1' }
    param :arg2
    option :option1
  end
end 

The interface is similar to dry-initializer + dry-containers where the containers are initialized “verb” like objects. Of course, an extension is to include descriptions for rendering help text to the end user. I’m basically building this by simply passing the options hash from thor to a class right now, but having this interact more seamlessly between would be really nice.


#2

As I know Tim already start playing with CLI, for sure it will be used for ROM and dry-web, but not thor (why not you can read in article), but hanami cli: https://github.com/hanami/cli


#3

Nice ideas, @kbacha, and definitely ones I’ve had before.

@gotar’s answer is pretty much on the mark: I’m currently early in the process of building a modular CLI for dry-{system,web,web-roda} and I’m basing it on top of hanami-cli. It does pretty much everything I would’ve wanted in a modern CLI library, so I’m using that.