Module: PiotrbCliUtils::CriCommandSupport
- Defined in:
- lib/piotrb_cli_utils/cri_command_support.rb
Instance Method Summary collapse
Instance Method Details
#define_cmd(name, summary: nil, help: false, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/piotrb_cli_utils/cri_command_support.rb', line 5 def define_cmd(name, summary: nil, help: false, &block) cmd_name = name Cri::Command.define do name cmd_name summary summary option nil, :help, 'show help for this command' run do |opts, args, cmd| if opts[:help] puts cmd.help else if block block.call(opts, args, cmd) elsif help puts cmd.help else warn "no action defined for cmd: #{cmd.name}" end end end end end |
#exit_cmd ⇒ Object
27 28 29 30 31 |
# File 'lib/piotrb_cli_utils/cri_command_support.rb', line 27 def exit_cmd define_cmd('exit') do |_opts, _args, _cmd| throw :stop, :exit end end |