class MisterBin::Command

Attributes

args[R]

Public Class Methods

command(name, text) click to toggle source
# File lib/mister_bin/command.rb, line 49
def command(name, text)
  target_commands << name.to_sym
  meta.commands << [name, text]
end
environment(name, value) click to toggle source
# File lib/mister_bin/command.rb, line 62
def environment(name, value)
  meta.env_vars << [name, value]
end
example(text) click to toggle source
# File lib/mister_bin/command.rb, line 58
def example(text)
  meta.examples << text
end
execute(argv=[]) click to toggle source
# File lib/mister_bin/command.rb, line 15
def execute(argv=[])
  args = Docopt.docopt docopt, version: meta.version, argv: argv
  instance = new args
  target = find_target_command instance, args
  exitcode = instance.send target
  exitcode.is_a?(Numeric) ? exitcode : 0

rescue Docopt::Exit => e
  puts e.message
  1
end
help(text) click to toggle source
# File lib/mister_bin/command.rb, line 33
def help(text)
  meta.help = text
end
meta() click to toggle source
# File lib/mister_bin/command.rb, line 66
def meta
  @meta ||= CommandMeta.new
end
new(args = nil) click to toggle source
# File lib/mister_bin/command.rb, line 10
def initialize(args = nil)
  @args = args
end
option(flags, text) click to toggle source
# File lib/mister_bin/command.rb, line 45
def option(flags, text)
  meta.options << [flags, text]
end
param(param, text) click to toggle source
# File lib/mister_bin/command.rb, line 54
def param(param, text)
  meta.params << [param, text]
end
summary(text) click to toggle source

DSL

# File lib/mister_bin/command.rb, line 29
def summary(text)
  meta.summary = text
end
usage(text) click to toggle source
# File lib/mister_bin/command.rb, line 41
def usage(text)
  meta.usages << text
end
version(text) click to toggle source
# File lib/mister_bin/command.rb, line 37
def version(text)
  meta.version = text
end

Protected Class Methods

docopt() click to toggle source
# File lib/mister_bin/command.rb, line 72
def docopt
  meta.docopt
end

Private Class Methods

find_target_command(instance, args) click to toggle source
# File lib/mister_bin/command.rb, line 82
def find_target_command(instance, args)
  target_commands.each do |target|
    method_name = :"#{target}_command"
    return method_name if instance.respond_to? method_name and args[target.to_s]
  end
  :run
end
target_commands() click to toggle source
# File lib/mister_bin/command.rb, line 78
def target_commands
  @target_commands ||= []
end