Class: Govspeak::CLI

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/govspeak/cli.rb

Instance Method Summary collapse

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/govspeak/cli.rb', line 9

def run
  program(:name, 'Govspeak')
  program(:version, Govspeak::VERSION)
  program(:description, "A tool for rendering the GOV.UK dialect of markdown into HTML")
  default_command(:render)
  command(:render) do |command|
    command.syntax = "govspeak render [options] <input>"
    command.description = "Render Govspeak into HTML, can be sourced from stdin, as an argument or from a file"
    command.option("--file FILENAME", String, "File to render")
    command.option("--options JSON", String, "JSON to use as options")
    command.option("--options-file FILENAME", String, "A file of JSON options")
    command.action do |args, options|
      input = get_input($stdin, args, options)
      raise "Nothing to render. Use --help for assistance" unless input
      puts Govspeak::Document.new(input, govspeak_options(options)).to_html
    end
  end
  run!
end