Sha256: f4d14dd7608846cebb7c5a6926c0a8304cbbceb0c3bb924dab409269ad7fb78f
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
require 'ostruct' require 'optparse' require 'term/ansicolor' require 'git-whistles/logger' module Git::Whistles class App def initialize @options = OpenStruct.new(defaults) @log = Git::Whistles::Logger.new($stderr) end def main(args) parse_args!(args) end def self.run! new.main(ARGV) end protected # default options hash def defaults {} end attr :options attr :log def option_parser @option_parser ||= OptionParser.new do |op| op.banner = "Usage: #{$0}" end end def parse_args!(args) begin option_parser.parse!(args) rescue OptionParser::InvalidOption => error die error.message, :usage => true end end def run(command) %x(#{command}) end def run!(command) result = %x(#{command}) return result if $? == 0 die "command '#{command}' failed" end def die(message, options = {}) puts Term::ANSIColor.red(message) if options[:usage] puts puts option_parser.help end exit 1 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
git-whistles-0.6.1 | lib/git-whistles/app.rb |