Class: Rodolfo::CLI

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

Overview

Rodolfo CLI

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rodolfo/cli.rb', line 46

def self.exit_on_failure?
  true
end

Instance Method Details

#__print_versionObject



53
54
55
# File 'lib/rodolfo/cli.rb', line 53

def __print_version
  puts VERSION
end

#help(*args, &block) ⇒ Object



85
86
87
88
# File 'lib/rodolfo/cli.rb', line 85

def help(*args, &block)
  puts "Rodolfo v#{Rodolfo::VERSION}"
  super(*args, &block)
end

#read(pdf) ⇒ Object



63
64
65
# File 'lib/rodolfo/cli.rb', line 63

def read(pdf)
  puts Rodolfo::Reader.new(pdf).to_json
end

#render(recipe_path) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rodolfo/cli.rb', line 71

def render(recipe_path)
  file_name = options['save-to']
  strict = options['strict']

  data = $stdin.tty? ? {} : JSON.parse($stdin.read, symbolize_names: true)
  content = Rodolfo::Renderer.new(recipe_path, data, strict).render

  file_name ? File.write(file_name, content) : STDOUT.write(content)
  exit 0
rescue RenderError, SchemaValidationError => error
  STDOUT.write error.errors.to_json
  exit 2
end

#schema(recipe_path) ⇒ Object



58
59
60
# File 'lib/rodolfo/cli.rb', line 58

def schema(recipe_path)
  puts Rodolfo::Renderer.new(recipe_path, {}).json_schema
end