puppet-cleaner 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.3.0 2013-05-05
2
+ -----------------
3
+ Features:
4
+ * New worker for quoting resource titles (-r option)
5
+
1
6
  0.2.1 2013-05-03
2
7
  -----------------
3
8
  Bug fix:
data/README.md CHANGED
@@ -12,6 +12,11 @@ Requirements
12
12
 
13
13
  * puppet
14
14
 
15
+ Installation
16
+ ------------
17
+
18
+ sudo gem install puppet-cleaner
19
+
15
20
  Utilities
16
21
  ------------
17
22
 
@@ -22,6 +27,10 @@ applying the set of transformation rules that you select. If no options
22
27
  are selected all of them are applied, which currently is a subset of the
23
28
  puppet style guide.
24
29
 
30
+ **Note:** the use of `${}` for variable interpolation in strings and the
31
+ replacement of double with single quotes when possible are done by default
32
+ and are not optional.
33
+
25
34
  Usage:
26
35
 
27
36
  puppet-clean [-h] [-t n] [-abedlmovw ] file.pp [file2.pp...]
@@ -30,14 +39,15 @@ puppet style guide.
30
39
  -h, --help this help message
31
40
  -d, --debug prints tokens before and after the transformation
32
41
 
33
- -a, --alignfarrow aligns fat arrow (=>)
42
+ -a, --alignfarrow aligns fat arrows (`=>`)
34
43
  -b, --quotedbooleans removes unneeded quotes around boolean literals
35
- -e, --ensurefirst moves 'ensure' parameter to the top
36
- -l, --link uses ensure => link and target for symbolic links
37
- -m, --mlcomments converts /* */ style comments into #
38
- -o, --octalmode uses a 4 digit string for file modes
44
+ -e, --ensurefirst moves `ensure` attribute to the top
45
+ -l, --link declares symbolic links by using `ensure => link` and `target` attributes
46
+ -m, --mlcomments converts /* */ style comments to #
47
+ -o, --octalmode represents file modes as a 4 digits string
48
+ -r, --resourcetitles quotes resource titles
39
49
  -t n, --softtabs n indents by n spaces
40
- -v, --quotedvariables removes unneeded quotes around variables
50
+ -v, --quotedvariables emoves unneeded quotes around variables
41
51
  -w, --trailingws removes trailing white space
42
52
 
43
53
  ### puppet-diff
@@ -46,12 +56,22 @@ Receives two puppet manifest files and outputs its difference, after
46
56
  converting them to YAML. Useful for verifying what (if anything) has
47
57
  changed after applying puppet-clean.
48
58
 
59
+ Usage:
60
+ puppet-diff [-h] [-w] old.pp new.pp
61
+
62
+ Options:
63
+ -h, --help this help message
64
+ -w, --write write a YAML file for each pp file if they are different
65
+
49
66
  ### puppet-inspect
50
67
 
51
68
  Receives a puppet manifest file and converts its objects (defined types,
52
69
  classes and nodes) to YAML.
53
70
 
71
+ Usage:
72
+ puppet-inspect file.pp
73
+
54
74
  Help & Feedback
55
- ------------
75
+ ---------------
56
76
 
57
- Mail me directly if you need help or have any feedback about it.
77
+ You can mail me directly if you need help or have any feedback to share.
data/bin/puppet-clean CHANGED
@@ -19,6 +19,7 @@ Options:
19
19
  -l, --link uses ensure => link and target for symbolic links
20
20
  -m, --mlcomments converts /* */ style comments into #
21
21
  -o, --octalmode uses a 4 digit string for file modes
22
+ -r, --resourcetitles quotes resource titles
22
23
  -t n, --softtabs n indents by n spaces
23
24
  -v, --quotedvariables removes unneeded quotes around variables
24
25
  -w, --trailingws removes trailing white space
@@ -36,6 +37,7 @@ opts = GetoptLong.new(
36
37
  [ '--link', '-l', GetoptLong::NO_ARGUMENT ],
37
38
  [ '--mlcomments', '-m', GetoptLong::NO_ARGUMENT ],
38
39
  [ '--octalmode', '-o', GetoptLong::NO_ARGUMENT ],
40
+ [ '--resourcetitles', '-r', GetoptLong::NO_ARGUMENT ],
39
41
  [ '--softtabs', '-t', GetoptLong::REQUIRED_ARGUMENT ],
40
42
  [ '--quotedvariables', '-v', GetoptLong::NO_ARGUMENT ],
41
43
  [ '--trailingws', '-w', GetoptLong::NO_ARGUMENT ]
@@ -62,6 +64,8 @@ opts.each do |opt, arg|
62
64
  workers << Puppet::Cleaner::MultilineComments.new
63
65
  when '--octalmode'
64
66
  workers << Puppet::Cleaner::OctalMode.new
67
+ when '--resourcetitles'
68
+ workers << Puppet::Cleaner::ResourceTitles.new
65
69
  when '--softtabs'
66
70
  tabstop = arg.to_i <= 2 ? 2 : arg.to_i
67
71
  workers << Puppet::Cleaner::SoftTabs.new(tabstop)
@@ -83,6 +87,7 @@ ALL = [
83
87
  Puppet::Cleaner::TrailingWhitespaceInComments.new,
84
88
  Puppet::Cleaner::AlignFarrow.new,
85
89
  Puppet::Cleaner::OctalMode.new,
90
+ Puppet::Cleaner::ResourceTitles.new,
86
91
  Puppet::Cleaner::EnsureFirst.new,
87
92
  Puppet::Cleaner::QuotedBooleans.new,
88
93
  Puppet::Cleaner::Symlink.new
@@ -0,0 +1,42 @@
1
+ module Puppet::Cleaner
2
+ class ResourceTitles < Worker
3
+ def part_names
4
+ [:LBRACE]
5
+ end
6
+
7
+ def operate(line)
8
+ pos = line.position - 1
9
+ pos -= 1 while [:BLANK, :RETURN, :COMMENT, :MLCOMMENT].include?(line.parts[pos].name) && pos >= 0
10
+ return if pos < 0 || ![:NAME, :CLASS].include?(line.parts[pos].name)
11
+
12
+ pos -= 1
13
+ pos -= 1 while [:BLANK, :RETURN, :COMMENT, :MLCOMMENT].include?(line.parts[pos].name) && pos >= 0
14
+ return if [:CASE, :IF].include?(line.parts[pos].name)
15
+
16
+ foreach_title(line) do |pos|
17
+ if [:NAME, :CLASSREF].include?(line.parts[pos].name)
18
+ line.parts[pos] = Part.create([:STRING, {:value => line.parts[pos].value}])
19
+ end
20
+ end
21
+ end
22
+
23
+ def foreach_title(line)
24
+ depth = 1
25
+ pos = line.position
26
+
27
+ loop do
28
+ pos += 1
29
+ break if depth == 0 || pos >= line.parts.size
30
+ case line.parts[pos].name
31
+ when :LBRACE
32
+ depth += 1
33
+ when :RBRACE
34
+ depth -= 1
35
+ when :COLON
36
+ next if depth != 1
37
+ yield pos - 1
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end # module
metadata CHANGED
@@ -1,54 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: puppet-cleaner
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
4
5
  prerelease:
5
- version: 0.2.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Gerardo Santana Gomez Garrido
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2013-05-03 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: puppet
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :runtime
25
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
26
30
  description: Cleans puppet source code
27
31
  email: gerardo.santana@gmail.com
28
- executables:
32
+ executables:
29
33
  - puppet-diff
30
34
  - puppet-inspect
31
35
  - puppet-clean
32
36
  extensions: []
33
-
34
37
  extra_rdoc_files: []
35
-
36
- files:
38
+ files:
37
39
  - lib/puppet-cleaner.rb
38
- - lib/puppet-cleaner/inspect.rb
39
- - lib/puppet-cleaner/line.rb
40
40
  - lib/puppet-cleaner/parts.rb
41
+ - lib/puppet-cleaner/line.rb
42
+ - lib/puppet-cleaner/inspect.rb
41
43
  - lib/puppet-cleaner/workers.rb
44
+ - lib/puppet-cleaner/workers/quotedbooleans.rb
45
+ - lib/puppet-cleaner/workers/unneededquotes.rb
46
+ - lib/puppet-cleaner/workers/multilinecomments.rb
47
+ - lib/puppet-cleaner/workers/trailingwhitespaceincomments.rb
48
+ - lib/puppet-cleaner/workers/trailingwhitespace.rb
49
+ - lib/puppet-cleaner/workers/symlink.rb
42
50
  - lib/puppet-cleaner/workers/alignfarrow.rb
43
51
  - lib/puppet-cleaner/workers/ensurefirst.rb
44
- - lib/puppet-cleaner/workers/multilinecomments.rb
45
52
  - lib/puppet-cleaner/workers/octalmode.rb
46
- - lib/puppet-cleaner/workers/quotedbooleans.rb
53
+ - lib/puppet-cleaner/workers/resourcetitles.rb
47
54
  - lib/puppet-cleaner/workers/softtabs.rb
48
- - lib/puppet-cleaner/workers/symlink.rb
49
- - lib/puppet-cleaner/workers/trailingwhitespace.rb
50
- - lib/puppet-cleaner/workers/trailingwhitespaceincomments.rb
51
- - lib/puppet-cleaner/workers/unneededquotes.rb
52
55
  - COPYRIGHT
53
56
  - Changelog
54
57
  - README.md
@@ -57,30 +60,26 @@ files:
57
60
  - bin/puppet-clean
58
61
  homepage: http://puppet-cleaner.rubyforge.org/
59
62
  licenses: []
60
-
61
63
  post_install_message:
62
64
  rdoc_options: []
63
-
64
- require_paths:
65
+ require_paths:
65
66
  - lib
66
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
67
68
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: "0"
72
- required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
78
79
  requirements: []
79
-
80
80
  rubyforge_project: puppet-cleaner
81
- rubygems_version: 1.8.11
81
+ rubygems_version: 1.8.23
82
82
  signing_key:
83
83
  specification_version: 3
84
84
  summary: Puppet Source Code Cleaner
85
85
  test_files: []
86
-