Module: Xdrgen::CLI

Defined in:
lib/xdrgen/cli.rb

Class Method Summary collapse

Class Method Details

.fail(slop, code = 1) ⇒ Object



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

def self.fail(slop, code=1)
  STDERR.puts slop
  exit(code)
end

.run(args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/xdrgen/cli.rb', line 5

def self.run(args)
  args = args.dup
  opts = Slop.parse! args do
    banner 'Usage: xdrgen -o OUTPUT_DIR INPUT --language=ruby'
    on 'o', 'output=', 'The output directory'
    on 'l', 'language=', 'The output language', default: 'ruby'
    on 'n', 'namespace=', '"namespace" to generate code within (language-specific)'
  end

  fail(opts) if args.blank?
  fail(opts) if opts[:output].blank?

  compilation = Compilation.new(
    args,
    output_dir: opts[:output],
    language:   opts[:language].to_sym,
    namespace:  opts[:namespace]
  )
  compilation.compile
end