Class: Yome::Cli

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

Class Method Summary collapse

Class Method Details

.exec(argv = []) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/yome/cli.rb', line 10

def self.exec(argv = [])
  opt = {lang: ""}

  parser = OptionParser.new("Usage: yome [DIR] [options]")
  parser.on('-o FILE', 'Output file name') {|v| opt[:output] = v }
  parser.on('--lang LANG', 'Specify code blocks language') {|v| opt[:lang] = v }
  parser.parse!(argv)

  dir = argv[0] || "."
  main(dir, opt)
end

.main(dir, opt) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/yome/cli.rb', line 22

def self.main(dir, opt)
  parser = Parser.new(dir)
  writer = Writer.new(parser, opt[:lang])

  if opt[:output]
    File.write(opt[:output], writer.result)
  else
    puts writer.result
  end
end