Class: Antelope::CLI

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

Overview

Handles the command line interface.

Instance Method Summary collapse

Instance Method Details

#check(*files) ⇒ Object

Check.



26
27
28
29
30
# File 'lib/antelope/cli.rb', line 26

def check(*files)
  files.each do |file|
    compile_file(file, [Generator::Null])
  end
end

#compile(*files) ⇒ Object

Compile.



17
18
19
20
21
# File 'lib/antelope/cli.rb', line 17

def compile(*files)
  files.each do |file|
    compile_file(file)
  end
end

#compile_file(file, gen = :guess) ⇒ void (private)

This method returns an undefined value.

Compiles the given file, and then generates. If an error occurs, it prints it out to stderr, along with a backtrace if the verbose flag was set.

Parameters:

  • file (String)

    the file to compile.

  • gen (Array, Symbol) (defaults to: :guess)

    the generator to use.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/antelope/cli.rb', line 46

def compile_file(file, gen = :guess)
  puts "Compiling #{file}... "

  grammar = Grammar.from_file(file)
  grammar.generate(options, gen)

rescue => e
  $stderr.puts "Error while compiling: #{e.class}: #{e.message}"

  if options[:verbose]
    $stderr.puts e.backtrace[0..10].map { |_| "\t#{_}" }
  end
end

#versionObject



33
34
35
# File 'lib/antelope/cli.rb', line 33

def version
  puts "Antelope version #{Antelope::VERSION}"
end