Sha256: 72e1f26b1d347028fc022d87163acbf1ab7a52a8f5aaf6036af1dbde59da8f45
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
require 'colored2' require 'optparse' require 'hashie/mash' require 'saves/cli/parser' require 'forwardable' module Saves module CLI class App extend Forwardable def_delegators :@parser, :options, :output attr_accessor :args, :command, :parser, :options, :output def initialize(args) if args.nil? || args.empty? self.args = %w[--help] else self.args = args.dup end self.parser = ::Saves::CLI::Parser self.options = parser.options self.output = parser.output end def parse! if args.first =~ /^-/ parser.global.parse!(args) else cmd = self.args.shift.to_sym begin Parser.parser_for(cmd).parse!(args) self.command = cmd # did not raise exception, so valid command. rescue Saves::CLI::InvalidCommandError => e options[:errors] = [e.message] end end end def out output.join("\n") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arli-0.2.1 | lib/arli/app.rb |