Class: Sangi::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sangi/cli.rb

Constant Summary collapse

SEPARATOR =
"=" * 60

Instance Method Summary collapse

Instance Method Details

#run(argv) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sangi/cli.rb', line 7

def run(argv)
  args = argv.dup
  expression_source = extract_expression!(args)
  options, parser = parse_options(args)
  if options[:help]
    puts parser
    return 0
  end
  if options[:version]
    puts VERSION
    return 0
  end

  expression_source ||= args.shift
  raise ParseError, "式は1つだけ指定してください。" unless args.empty?

  config = build_config(options)
  return REPL.new(config: config).start if expression_source.nil?

  run_expression(expression_source, config)
  0
rescue OptionParser::ParseError => e
  warn e.message
  1
rescue Sangi::Error => e
  warn e.message
  warn e.full_message if ENV["SANGI_DEBUG"] == "1"
  1
end