We accidentally omitted whitespace between multiple options while building the
synopsis.  This fixes that, by introducing a breakable space in the right
location.

Additionally, we extract the code that was 99 percent identical from the face
and action synopsis generators, push it down into the documentation module,
and then invoke it from both places.

This eliminates the duplicate code, allowing me to fix that bug once and have
it apply to both parts of the code; this is pretty much assured to be true
any time we change the synopsis generation.

Reviewed-By: Nick Fagerlund <[email protected]>
---
 lib/puppet/interface.rb                   |   21 +-----------------
 lib/puppet/interface/action.rb            |   23 +------------------
 lib/puppet/interface/documentation.rb     |   31 ++++++++++++++++++++++++++
 spec/unit/interface/documentation_spec.rb |   34 +++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 42 deletions(-)
 create mode 100755 spec/unit/interface/documentation_spec.rb

diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 10e2ec8..6be8b69 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -76,26 +76,7 @@ class Puppet::Interface
   # splits out this should merge into a module that both the action and face
   # include. --daniel 2011-04-17
   def synopsis
-    output = PrettyPrint.format do |s|
-      s.text("puppet #{name} <action>")
-      s.breakable
-
-      options.each do |option|
-        option = get_option(option)
-        wrap = option.required? ? %w{ < > } : %w{ [ ] }
-
-        s.group(0, *wrap) do
-          option.optparse.each do |item|
-            unless s.current_group.first?
-              s.breakable
-              s.text '|'
-              s.breakable
-            end
-            s.text item
-          end
-        end
-      end
-    end
+    build_synopsis self.name, '<action>'
   end
 
 
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index 748888c..185302b 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -48,28 +48,7 @@ class Puppet::Interface::Action
   attr_doc :returns
   attr_doc :arguments
   def synopsis
-    output = PrettyPrint.format do |s|
-      s.text("puppet #{@face.name}")
-      s.text(" #{name}") unless default?
-      s.breakable
-
-      options.each do |option|
-        option = get_option(option)
-        wrap = option.required? ? %w{ < > } : %w{ [ ] }
-
-        s.group(0, *wrap) do
-          option.optparse.each do |item|
-            unless s.current_group.first?
-              s.breakable
-              s.text '|'
-              s.breakable
-            end
-            s.text item
-          end
-        end
-      end
-      s.text(" #{arguments}") if arguments
-    end
+    build_synopsis(@face.name, default? ? nil : name, arguments)
   end
 
   ########################################################################
diff --git a/lib/puppet/interface/documentation.rb 
b/lib/puppet/interface/documentation.rb
index fcaec25..47e478a 100644
--- a/lib/puppet/interface/documentation.rb
+++ b/lib/puppet/interface/documentation.rb
@@ -61,6 +61,37 @@ class Puppet::Interface
     end
 
     attr_doc :description
+
+    def build_synopsis(face, action = nil, arguments = nil)
+      output = PrettyPrint.format do |s|
+        s.text("puppet #{face}")
+        s.text(" #{action}") unless action.nil?
+        s.text(" ")
+
+        options.each do |option|
+          option = get_option(option)
+          wrap = option.required? ? %w{ < > } : %w{ [ ] }
+
+          s.group(0, *wrap) do
+            option.optparse.each do |item|
+              unless s.current_group.first?
+                s.breakable
+                s.text '|'
+                s.breakable
+              end
+              s.text item
+            end
+          end
+
+          s.breakable
+        end
+
+        if arguments then
+          s.text arguments.to_s
+        end
+      end
+    end
+
   end
 
   module FullDocs
diff --git a/spec/unit/interface/documentation_spec.rb 
b/spec/unit/interface/documentation_spec.rb
new file mode 100755
index 0000000..6865b90
--- /dev/null
+++ b/spec/unit/interface/documentation_spec.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+require 'puppet/interface'
+require 'puppet/interface/option'
+require 'puppet/interface/documentation'
+
+class Puppet::Interface::TinyDocs::Test
+  include Puppet::Interface::TinyDocs
+  attr_accessor :name, :options
+  def initialize
+    self.name    = "tinydoc-test"
+    self.options = []
+  end
+
+  def get_option(name)
+    Puppet::Interface::Option.new(nil, "--#{name}")
+  end
+end
+
+describe Puppet::Interface::TinyDocs do
+  subject { Puppet::Interface::TinyDocs::Test.new }
+
+  context "#build_synopsis" do
+    before :each do
+      subject.options = [:foo, :bar]
+    end
+
+    it { should respond_to :build_synopsis }
+
+    it "should put a space between options (#7828)" do
+      subject.build_synopsis('baz').should =~ /#{Regexp.quote('[--foo] 
[--bar]')}/
+    end
+  end
+end
-- 
1.7.5.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to