Sha256: 769a87cddb9f2b3259c0b8fa5d98bc996796e6cf3dcbb55ac1ed4515fbd68f05

Contents?: true

Size: 903 Bytes

Versions: 1

Compression:

Stored size: 903 Bytes

Contents

#!/usr/bin/env ruby
require 'dmtool'
require 'optparse'

def opts_from_cli
  options = {}
  opt_parser = OptionParser.new do |opts|
    opts.program_name = File.basename(__FILE__)
    opts.banner = "#{opts.program_name} [options]"
    opts.on('-r', '--raw', 'Display raw results (ignores +/- modifiers)') { options[:raw] = true }
    opts.on('-v', '--version', 'Print version information') do
      puts "#{File.basename(__FILE__)} #{DMTool::VERSION}"
      exit true
    end
    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit true
    end
  end
  begin
    opt_parser.parse!
  rescue OptionParser::InvalidOption => e
    puts e.message
    exit false
  end
  options
end

def results_from(options)
  parser = DMTool::Parser.new
  input = ARGV.join(' ')
  command = options[:raw] ? 'raw' : 'roll'
  parser.parse("#{command} #{input}")
end

puts results_from(opts_from_cli)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dmtool-0.0.1 bin/roll