Sha256: 404aef6b5fc96063590f693261bcb3ac7924a4985f0e49fc43c6dbab38b3a023
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
require "optparse" module Twitchus class Cli attr_reader :options def initialize @options = {} end def parser @parser ||= OptionParser.new do |opts| opts.on("-c CONFIG", "Specify a config file.") do |config| @options[:config] = config end opts.on( "-h", "--help", "Display this message.") do |h| $stdout.puts opts.to_s exit 0 end opts.on( "-v", "--version", "Output the version of Twitchus.") do |v| $stdout.puts "Twitchus version #{Twitchus::VERSION}" exit 0 end end end def parse(argv, env) parser.parse! argv if @options[:config] if File.exists? @options[:config] worker = Twitchus::Worker.new(@options[:config]) worker.run exit 0 else raise OptionParser::ParseError, "The config file you specified doesn't exist" end else raise OptionParser::ParseError, "You must specify a config file." end return true rescue OptionParser::ParseError => e $stderr.puts e $stderr.puts $stderr.puts parser.help exit 1 end def run(argv = ARGV, env = ENV) parse(argv, env) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
twitchus-0.1.1 | lib/twitchus/cli.rb |
twitchus-0.1.0 | lib/twitchus/cli.rb |