module SheepAst::Option

Aggregates User interface of sheep_ast library

@api public

Public Instance Methods

command() click to toggle source
# File lib/sheep_ast/option.rb, line 103
def command
  if @optparse
    puts ''
    puts "Usage: #{@optparse.program_name} [options] arg1, arg2, ..."
    puts '    arg1, arg2, ... : specify files to parse.'
  end
end
do_configure(core, option = nil, optparse = nil) click to toggle source
# File lib/sheep_ast/option.rb, line 129
def do_configure(core, option = nil, optparse = nil)
  if defined? configure
    core.set_option(option, optparse)
    configure(core)
    return true
  end
  return false
end
load_config() click to toggle source
# File lib/sheep_ast/option.rb, line 90
def load_config
  config_file = @option[:r]
  if config_file
    if File.exist?(config_file)
      load config_file
    else
      application_error "#{config_file} could not be found at the specified directory."
    end
  else
    return nil
  end
end
option() click to toggle source
# File lib/sheep_ast/option.rb, line 120
def option
  @option
end
option_on() click to toggle source
# File lib/sheep_ast/option.rb, line 16
def option_on
  @option = {}
  @optparse = OptionParser.new do |opt|
    opt.on(
      '-E array', Array,
      'Specify directories to exclude files'
    ) { |v| @option[:E] = v }
    opt.on(
      '-I array', Array, 'Specify search directories for the include files'
    ) { |v| @option[:I] = v }
    opt.on(
      '-d', 'Dump Debug information'
    ) { @option[:d] = true }
    opt.on(
      '-r file', 'Specify configuration ruby file'
    ) { |v| @option[:r] = v }
    opt.on(
      '-o path', 'outdir variable is set in the let_compile module'
    ) { |v| @option[:o] = v }
    opt.on(
      '-t array', Array,
      'Specify search directories for the template files for let_compile module'
    ) { |v| @option[:t] = v }
    opt.on_tail(
      '-h', '--help', 'show usage'
    ) { |_v| @option[:h] = true }
    opt.on_tail(
      '-v', '--version', 'show version'
    ) { |_v| @option[:v] = true }
  end
  return @optparse
end
option_parse(argv) click to toggle source
# File lib/sheep_ast/option.rb, line 62
def option_parse(argv)
  @optparse.parse!(argv)
  show_usage
  show_version
  load_config
  return @option
end
ruby_version() click to toggle source
# File lib/sheep_ast/option.rb, line 85
def ruby_version
  "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
end
set_option(opt, optp) click to toggle source
# File lib/sheep_ast/option.rb, line 124
def set_option(opt, optp)
  @option = opt
  @optparse = optp
end
show_usage() click to toggle source
# File lib/sheep_ast/option.rb, line 70
def show_usage
  if @option[:h]
    command
    usage
    exit
  end
end
show_version() click to toggle source
# File lib/sheep_ast/option.rb, line 78
def show_version
  if @option[:v]
    puts SheepAst::VERSION
    exit
  end
end
usage() click to toggle source
# File lib/sheep_ast/option.rb, line 111
def usage
  if @optparse
    puts ''
    @optparse.banner = 'Available options :'
    puts @optparse.help
    puts ''
  end
end