svenfuchs/cl

View on GitHub
examples/readme/runner

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
$: << File.expand_path('lib')

module Git
  class Pull < Cl::Cmd
    register :'git:pull'

    arg :branch

    def run
      p cmd: registry_key, args: args
    end
  end
end

# With this class registered (and assuming the executable that calls `Cl` is
# `bin/run`) the default runner would recognize and run it:
#
# $ bin/run git:pull master # instantiates Git::Pull, and passes ["master"] as args
# $ bin/run git pull master # does the same

Cl.new('run').run(%w(git:pull master))
# Output:
#
#   {:cmd=>:"git:pull", :args=>["master"]}

Cl.new('run').run(%w(git pull master))
# Output:
#
#   {:cmd=>:"git:pull", :args=>["master"]}