class Facter::Cli

Constants

IGNORE_OPTIONS

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/facter/framework/cli/cli.rb, line 214
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 178
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 191
def add_commands_to_help
  help_command_options = +''
  Cli.commands
     .select { |_k, command_class| command_class.instance_of?(Thor::Command) }
     .each do |_k, command|
    help_command_options << build_option(command['name'], [], command['description'])
  end

  help_command_options
end
arg_parser(*args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 122
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 202
def build_option(name, aliases, description)
  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 160
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 170
def help_header(_args)
  path = File.join(File.dirname(__FILE__), '../../')

  Util::FileHelper.safe_read("#{path}fixtures/facter_help_header")
end
list_block_groups(*args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 137
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) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 149
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) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 102
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
query(*args) click to toggle source
# File lib/facter/framework/cli/cli.rb, line 113
def query(*args)
  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 131
def version(*_args)
  puts Facter::VERSION
end