Class: Twitchus::Cli
- Inherits:
-
Object
- Object
- Twitchus::Cli
- Defined in:
- lib/twitchus/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ Cli
constructor
A new instance of Cli.
- #parse(argv, env) ⇒ Object
- #parser ⇒ Object
- #run(argv = ARGV, env = ENV) ⇒ Object
Constructor Details
#initialize ⇒ Cli
Returns a new instance of Cli.
8 9 10 |
# File 'lib/twitchus/cli.rb', line 8 def initialize @options = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/twitchus/cli.rb', line 6 def @options end |
Instance Method Details
#parse(argv, env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/twitchus/cli.rb', line 32 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 |
#parser ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/twitchus/cli.rb', line 12 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 |
#run(argv = ARGV, env = ENV) ⇒ Object
56 57 58 |
# File 'lib/twitchus/cli.rb', line 56 def run(argv = ARGV, env = ENV) parse(argv, env) end |