Class: Facter::Cli

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/facter/framework/cli/cli.rb', line 216

def self.exit_on_failure?
  true
end

Instance Method Details

#arg_parser(*args) ⇒ Object



118
119
120
121
122
123
# File 'lib/facter/framework/cli/cli.rb', line 118

def arg_parser(*args)
  # ignore unknown options
  args.reject! { |arg| arg.start_with?('-') }

  Facter.values(@options, args)
end

#help(*args) ⇒ Object



162
163
164
165
166
167
168
169
# File 'lib/facter/framework/cli/cli.rb', line 162

def help(*args)
  help_string = +''
  help_string << help_header(args)
  help_string << add_class_options_to_help
  help_string << add_commands_to_help

  puts help_string
end

#list_block_groups(*args) ⇒ Object



133
134
135
136
137
138
139
140
141
# File 'lib/facter/framework/cli/cli.rb', line 133

def list_block_groups(*args)
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
  Facter::Options.init_from_cli(options, args)

  block_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..-1].join
  block_groups.gsub!(/:\s*\n/, "\n")

  puts block_groups
end

#list_cache_groups(*args) ⇒ Object



145
146
147
148
149
150
151
152
153
# File 'lib/facter/framework/cli/cli.rb', line 145

def list_cache_groups(*args)
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
  Facter::Options.init_from_cli(options, args)

  cache_groups = Facter::FactGroups.new.groups.to_yaml.lines[1..-1].join
  cache_groups.gsub!(/:\s*\n/, "\n")

  puts cache_groups
end

#man(*args) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/facter/framework/cli/cli.rb', line 98

def man(*args)
  require 'erb'
  negate_options = %w[block cache custom_facts external_facts]

  template = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'man.erb')
  erb = ERB.new(File.read(template), nil, '-')
  erb.filename = template
  puts erb.result(binding)
end

#puppet(*_args) ⇒ Object



157
158
159
# File 'lib/facter/framework/cli/cli.rb', line 157

def puppet(*_args)
  puts '`facter --puppet` and `facter -p` are no longer supported, use `puppet facts show` instead'
end

#query(*args) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/facter/framework/cli/cli.rb', line 109

def query(*args)
  output, status = Facter.to_user_output(@options, *args)
  puts output

  status = 1 if Facter::Log.errors?
  exit status
end

#version(*_args) ⇒ Object



127
128
129
# File 'lib/facter/framework/cli/cli.rb', line 127

def version(*_args)
  puts Facter::VERSION
end