#!/usr/bin/env ruby lib = File.expand_path(File.dirname(__FILE__) + '/../lib') $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib) require 'optparse' require_relative '../lib/typogrowth' options = {} OptionParser.new do |opts| opts.banner = "Usage: #{$0} FILE|STRING" # Bowl result? opts.on("-o", "--out FILE", "Output file name for result") do |outfile| options[:outfile] = outfile end # No argument, shows at tail. This will print an options summary. opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end.parse! raise "Run `#{$0} --help` for execution examples. Exiting…" if ARGV.size.zero? file_or_string = ARGV.first file_or_string = File.read(file_or_string) if File.exist?(file_or_string) @result = Typogrowth::parse file_or_string options[:outfile].nil? ? puts(@result) : File.write(options[:outfile], @result)