Skip to content

Commit 1cd0209

Browse files
committed
Add pry() function from hunner-pry
1 parent 7507af5 commit 1cd0209

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

README.markdown

+14
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,20 @@ For example:
935935

936936
*Type*: rvalue.
937937

938+
#### `pry`
939+
940+
This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation. Should only be used when running `puppet apply` or running a puppet master in the foreground. This requires the `pry` gem to be installed in puppet's rubygems.
941+
942+
*Examples:*
943+
```puppet
944+
pry()
945+
```
946+
Once in a pry session, some interesting commands:
947+
948+
* Run `catalog` to see the contents currently compiling catalog
949+
* Run `cd catalog` and `ls` to see catalog methods and instance variables
950+
* Run `@resource_table` to see the current catalog resource table
951+
938952
#### `assert_private`
939953

940954
Sets the current class or definition as private. Calling the class or definition from outside the current module will fail.

lib/puppet/parser/functions/pry.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# pry.rb
3+
#
4+
5+
module Puppet::Parser::Functions
6+
newfunction(:pry, :type => :statement, :doc => <<-EOS
7+
This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation.
8+
9+
*Examples:*
10+
11+
pry()
12+
EOS
13+
) do |arguments|
14+
begin
15+
require 'pry'
16+
rescue LoadError
17+
raise(Puppet::Error, "pry(): Requires the 'pry' rubygem to use, but it was not found")
18+
end
19+
#
20+
## Run `catalog` to see the contents currently compiling catalog
21+
## Run `cd catalog` and `ls` to see catalog methods and instance variables
22+
## Run `@resource_table` to see the current catalog resource table
23+
#
24+
if $stdout.isatty
25+
binding.pry # rubocop:disable Lint/Debugger
26+
else
27+
Puppet.warning 'pry(): cowardly refusing to start the debugger on a daemonized master'
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)