module Mybot::Cli
Public Instance Methods
parse_args(args)
click to toggle source
# File lib/mybot/cli.rb, line 19 def parse_args(args) options = {} args.each_with_index do |arg, i| case arg # --foo=bar, -foo=bar when /\=/ key, value = *arg.split("=") options[key.sub(/^-{1,2}/,"").to_sym] = value when /^-{1,2}no-(.+)/ # --no-foo options[$1.to_sym] = false when /^-{1,2}(.+)/ # --foo bar, --foo, -foo key = $1.to_sym value = true if args[i+1] && args[i+1] !~ /^-{1,2}/ value = args.delete_at(i+1) end options[key] = value when Hash options.merge!(arg) end end options.each do |k, v| case v when /^true$/i then options[k] = true when /^false$/i then options[k] = false when /^\d+$/ then options[k] = v.to_i when /^[\d\.]+$/ then options[k] = v.to_f when /,/ then options[k] = v.split(",").map(&:strip) end end end
start(args)
click to toggle source
# File lib/mybot/cli.rb, line 6 def start(args) cmd = args.shift options = parse_args(args) unless cmd print_cmd! "error", "usage: bot <task> [<options>]", :red, :bold abort end Base.load_recipes Base.run_task cmd, options end