Class: Consult::CLI

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/consult/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



14
15
16
# File 'lib/consult/cli.rb', line 14

def opts
  @opts
end

Instance Method Details

#parse(args = ARGV) ⇒ Object



16
17
18
19
# File 'lib/consult/cli.rb', line 16

def parse(args = ARGV)
  @opts = parse_options(args)
  Consult.load **@opts
end

#parse_options(argv) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/consult/cli.rb', line 25

def parse_options(argv)
  opts = {
    config_dir: Dir.pwd,
    force_render: true,
    verbose: true
  }

  @parser = OptionParser.new do |o|
    o.on '-d', '--directory=DIR', 'Path to directory containing the config directory' do |arg|
      opts[:config_dir] = arg
    end

    o.on '-f', '--[no-]force', TrueClass, 'Ignore template TTLs and force rendering' do |arg|
      opts[:force_render] = arg
    end

    o.on '--quiet', FalseClass, 'Silence output' do |arg|
      opts[:verbose] = arg
    end

    o.on '--version', 'Show version' do
      puts "Consult #{Consult::VERSION}"
      exit 0
    end
  end

  @parser.on_tail "-h", "--help", "Show help" do
    puts @parser
    exit 1
  end

  @parser.parse! argv
  opts
end

#renderObject



21
22
23
# File 'lib/consult/cli.rb', line 21

def render
  Consult.render!
end