class Facter::Cli

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/facter/framework/cli/cli.rb, line 227
def self.exit_on_failure?
  true
end

Public Instance Methods

add_class_options_to_help() click to toggle source
# File lib/facter/framework/cli/cli.rb, line 186
def add_class_options_to_help
  help_class_options = +''
  class_options = Cli.class_options
  class_options.each do |class_option|
    option = class_option[1]
    next if option.hide

    help_class_options << build_option(option.name, option.aliases, option.description)
  end

  help_class_options
end
add_commands_to_help() click to toggle source
# File lib/facter/framework/cli/cli.rb, line 199
def add_commands_to_help
  help_command_options = +''
  Cli.commands.values
     .select { |command_class| command_class.instance_of?(Thor::Command) }
     .each do |command|
    help_command_options << build_option(
      command['name'],
      [command['usage'].split(',')[1]],
      command['description']
    )
  end

  help_command_options
end
arg_parser(*args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 132
def arg_parser(*args)
  # ignore unknown options
  args.reject! { |arg| arg.start_with?('-') }

  Facter.values(@options, args)
end
build_option(name, aliases, description) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 214
def build_option(name, aliases, description)
  name = name.tr('_', '-')
  help_option = +''
  help_option << aliases.join(',').rjust(10)
  help_option << ' '
  help_option << "[--#{name}]".ljust(30)
  help_option << " #{description}"
  help_option << "\n"

  help_option
end
help(*args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 170
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
help_header(_args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 180
def help_header(_args)
  path = File.join(File.dirname(__FILE__), '../../')

  Facter::Util::FileHelper.safe_read("#{path}fixtures/facter_help_header")
end
list_block_groups() click to toggle source
# File lib/facter/framework/cli/cli.rb, line 147
def list_block_groups
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
  Facter::Options.init_from_cli(options)

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

  puts block_groups
end
list_cache_groups() click to toggle source
# File lib/facter/framework/cli/cli.rb, line 159
def list_cache_groups
  options = @options.map { |(k, v)| [k.to_sym, v] }.to_h
  Facter::Options.init_from_cli(options)

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

  puts cache_groups
end
man(*args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 111
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), trim_mode: '-')
  erb.filename = template
  puts erb.result(binding)
end
query(*args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 122
def query(*args)
  Facter.puppet_facts if options[:puppet]
  output, status = Facter.to_user_output(@options, *args)
  puts output

  status = 1 if Facter::Log.errors?
  exit status
end
version(*_args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 141
def version(*_args)
  puts Facter::VERSION
end