lib/puppet/application/debugger.rb in puppet-debugger-0.12.3 vs lib/puppet/application/debugger.rb in puppet-debugger-0.13.0
- old
+ new
@@ -1,46 +1,46 @@
# frozen_string_literal: true
-require 'puppet/application'
-require 'optparse'
-require 'puppet/util/command_line'
+require "puppet/application"
+require "optparse"
+require "puppet/util/command_line"
class Puppet::Application::Debugger < Puppet::Application
attr_reader :use_stdin
- option('--execute EXECUTE', '-e') do |arg|
+ option("--execute EXECUTE", "-e") do |arg|
options[:code] = arg
end
- option('--facterdb-filter FILTER') do |arg|
+ option("--facterdb-filter FILTER") do |arg|
options[:use_facterdb] = true unless options[:node_name]
- ENV['DEBUGGER_FACTERDB_FILTER'] = arg if arg
+ ENV["DEBUGGER_FACTERDB_FILTER"] = arg if arg
end
- option('--test') do |_arg|
+ option("--test") do |_arg|
options[:quiet] = true
options[:run_once] = true
@use_stdin = true
end
- option('--no-facterdb') { |_arg| options[:use_facterdb] = false }
+ option("--no-facterdb") { |_arg| options[:use_facterdb] = false }
- option('--log-level LEVEL', '-l') do |arg|
+ option("--log-level LEVEL", "-l") do |arg|
Puppet::Util::Log.level = arg.to_sym
end
- option('--quiet', '-q') { |_arg| options[:quiet] = true }
+ option("--quiet", "-q") { |_arg| options[:quiet] = true }
- option('--play URL', '-p') do |arg|
+ option("--play URL", "-p") do |arg|
options[:play] = arg
end
- option('--stdin', '-s') { |_arg| @use_stdin = true }
+ option("--stdin", "-s") { |_arg| @use_stdin = true }
- option('--run-once', '-r') { |_arg| options[:run_once] = true }
+ option("--run-once", "-r") { |_arg| options[:run_once] = true }
- option('--node-name CERTNAME', '-n') do |arg|
+ option("--node-name CERTNAME", "-n") do |arg|
options[:use_facterdb] = false
options[:node_name] = arg
end
def help
@@ -176,57 +176,62 @@
def initialize(command_line = Puppet::Util::CommandLine.new)
@command_line = CommandLineArgs.new(command_line.subcommand_name, command_line.args.dup)
@options = { use_facterdb: true, play: nil, run_once: false, node_name: nil, quiet: false, help: false, scope: nil }
@use_stdin = false
begin
- require 'puppet-debugger'
+ require "puppet-debugger"
rescue LoadError => e
- Puppet.err('You must install the puppet-debugger: gem install puppet-debugger')
+ Puppet.err("You must install the puppet-debugger: gem install puppet-debugger")
end
end
def main
# if this is a file we don't play back since its part of the environment
# if just the code we put in a file and use the play feature of the debugger
# we could do the same thing with the passed in manifest file but that might be too much code to show
if options[:code]
code_input = options.delete(:code)
- file = Tempfile.new(['puppet_repl_input', '.pp'])
- File.open(file, 'w') do |f|
+ file = Tempfile.new(["puppet_repl_input", ".pp"])
+ File.open(file, "w") do |f|
f.write(code_input)
end
options[:play] = file
elsif command_line.args.empty? && use_stdin
code_input = STDIN.read
- file = Tempfile.new(['puppet_repl_input', '.pp'])
- File.open(file, 'w') do |f|
+ file = Tempfile.new(["puppet_repl_input", ".pp"])
+ File.open(file, "w") do |f|
f.write(code_input)
end
options[:play] = file
elsif !command_line.args.empty?
manifest = command_line.args.shift
raise "Could not find file #{manifest}" unless Puppet::FileSystem.exist?(manifest)
- Puppet.warning("Only one file can be used per run. Skipping #{command_line.args.join(', ')}") unless command_line.args.empty?
+ Puppet.warning("Only one file can be used per run. Skipping #{command_line.args.join(", ")}") unless command_line.args.empty?
options[:play] = file
end
- if !options[:use_facterdb] && options[:node_name].nil?
- debug_environment = create_environment(nil)
- Puppet.notice('Gathering node facts...')
- node = create_node(debug_environment)
- scope = create_scope(node)
- # start_debugger(scope)
- options[:scope] = scope
+ begin
+ if !options[:use_facterdb] && options[:node_name].nil?
+ debug_environment = create_environment(nil)
+ Puppet.notice('Gathering node facts...')
+ node = create_node(debug_environment)
+ scope = create_scope(node)
+ # start_debugger(scope)
+ options[:scope] = scope
+ end
+ ::PuppetDebugger::Cli.start_without_stdin(options)
+ rescue Exception => e
+ puts e
+ exit 1
end
- ::PuppetDebugger::Cli.start_without_stdin(options)
end
def create_environment(manifest)
configured_environment = Puppet.lookup(:current_environment)
manifest ?
- configured_environment.override_with(manifest: manifest) :
- configured_environment
+ configured_environment.override_with(manifest: manifest) :
+ configured_environment
end
def create_node(environment)
node = nil
unless Puppet[:node_name_fact].empty?
@@ -235,11 +240,11 @@
raise "Could not find facts for #{Puppet[:node_name_value]}"
end
Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
facts.name = Puppet[:node_name_value]
end
- Puppet.override({ current_environment: environment }, 'For puppet debugger') do
+ Puppet.override({ current_environment: environment }, "For puppet debugger") do
# Find our Node
unless node = Puppet::Node.indirection.find(Puppet[:node_name_value])
raise "Could not find node #{Puppet[:node_name_value]}"
end
# Merge in the facts.
@@ -266,10 +271,10 @@
# required in order to use convert puppet hash into ruby hash with symbols
options = options.each_with_object({}) { |(k, v), data| data[k.to_sym] = v; data }
# options[:source_file], options[:source_line] = stacktrace.last
::PuppetRepl::Cli.start(options)
else
- Puppet.info 'puppet debug: refusing to start the debugger without a tty'
+ Puppet.info "puppet debug: refusing to start the debugger without a tty"
end
end
# returns a stacktrace of called puppet code
# @return [String] - file path to source code