class Inspec::EnvPrinter
Constants
- EVAL_COMMANDS
Attributes
shell[R]
Public Class Methods
new(command_class, shell = nil)
click to toggle source
# File lib/inspec/env_printer.rb, line 15 def initialize(command_class, shell = nil) if !shell @detected = true @shell = Inspec::ShellDetector.new.shell else @shell = shell end @command_class = command_class end
Public Instance Methods
print_and_exit!()
click to toggle source
# File lib/inspec/env_printer.rb, line 25 def print_and_exit! exit_no_shell unless have_shell? exit_no_completion unless have_shell_completion? print_completion_for_shell print_detection_warning($stdout) if @detected print_usage_guidance exit 0 end
Private Instance Methods
completion_dir()
click to toggle source
# File lib/inspec/env_printer.rb, line 50 def completion_dir File.join(File.dirname(__FILE__), "completions") end
completion_template_path()
click to toggle source
# File lib/inspec/env_printer.rb, line 54 def completion_template_path File.join(completion_dir, "#{@shell}.sh.erb") end
exit_no_completion()
click to toggle source
# File lib/inspec/env_printer.rb, line 85 def exit_no_completion $stderr.puts "# No completion script for #{@shell}!" print_detection_warning($stderr) if @detected exit 1 end
exit_no_shell()
click to toggle source
# File lib/inspec/env_printer.rb, line 91 def exit_no_shell if @detected $stderr.puts "# Unable to automatically detect shell and no shell was provided." end $stderr.puts <<~EOF # # Please provide the name of your shell via the command line: # # inspec env SHELLNAME # # Currently supported shells are: #{shells_with_completions.join(", ")} EOF exit 1 end
have_shell?()
click to toggle source
# File lib/inspec/env_printer.rb, line 42 def have_shell? !(@shell.nil? || @shell.empty?) end
have_shell_completion?()
click to toggle source
# File lib/inspec/env_printer.rb, line 46 def have_shell_completion? File.exist?(completion_template_path) end
print_completion_for_shell()
click to toggle source
# File lib/inspec/env_printer.rb, line 37 def print_completion_for_shell erb = ERB.new(File.read(completion_template_path), nil, "-") puts erb.result(TemplateContext.new(@command_class).get_bindings) end
print_detection_warning(device)
click to toggle source
# File lib/inspec/env_printer.rb, line 72 def print_detection_warning(device) device.puts <<~EOF # # The shell #{@shell} was auto-detected. If this is incorrect, please # specify a shell explicitly by running: # # inspec env SHELLNAME # # Currently supported shells are: #{shells_with_completions.join(", ")} # EOF end
print_usage_guidance()
click to toggle source
# File lib/inspec/env_printer.rb, line 62 def print_usage_guidance puts <<~EOF # To use this, eval it in your shell # # #{EVAL_COMMANDS[shell]} # # EOF end
shells_with_completions()
click to toggle source
# File lib/inspec/env_printer.rb, line 58 def shells_with_completions Dir.glob("#{completion_dir}/*.sh.erb").map { |f| File.basename(f, ".sh.erb") } end