[Pkg-puppet-devel] [facter] 02/352: (#15586) Use OptionParser for help

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 132c0ce72ee280137e8bf9936684699004c53c6c
Author: Andrew Parker <andy at puppetlabs.com>
Date:   Tue Aug 20 13:56:34 2013 -0700

    (#15586) Use OptionParser for help
    
    Ruby 1.9.3 dropped Rdoc.usage. The output of `facter --help` depended on
    this command. The suggested change from the Rdoc maintainer is to use
    the banner of the OptionParser instead. This changes it to use the
    banner.
---
 bin/facter                | 58 -----------------------------
 lib/facter/application.rb | 93 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 69 insertions(+), 82 deletions(-)

diff --git a/bin/facter b/bin/facter
index 686f880..0616157 100755
--- a/bin/facter
+++ b/bin/facter
@@ -1,62 +1,4 @@
 #!/usr/bin/env ruby
-#
-# = Synopsis
-#
-# Collect and display facts about the system.
-#
-# = Usage
-#
-#   facter [-d|--debug] [-h|--help] [-p|--puppet] [-v|--version] [-y|--yaml] [-j|--json] [--external-dir DIR] [--no-external-dir] [fact] [fact] [...]
-#
-# = Description
-#
-# Collect and display facts about the current system.  The library behind
-# Facter is easy to expand, making Facter an easy way to collect information
-# about a system from within the shell or within Ruby.
-#
-# If no facts are specifically asked for, then all facts will be returned.
-#
-# = Options
-#
-# yaml::
-#   Emit facts in YAML format.
-#
-# json::
-#   Emit facts in JSON format.
-#
-# puppet::
-#   Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.
-#
-# version::
-#   Print the version and exit.
-#
-# help::
-#   Print this help message.
-#
-# debug::
-#   Enable debugging.
-#
-# trace::
-#   Enable backtraces.
-#
-# timing::
-#   Enable timing.
-#
-# facts.d::
-#   The directory to use for external facts.
-#
-# = Example
-#
-#   facter kernel
-#
-# = Author
-#
-# Luke Kanies
-#
-# = Copyright
-#
-# Copyright (c) 2011 Puppet Labs, Inc
-# Licensed under the Apache 2.0 license
 
 # Bundler and rubygems maintain a set of directories from which to
 # load gems. If Bundler is loaded, let it determine what can be
diff --git a/lib/facter/application.rb b/lib/facter/application.rb
index 514021c..d94be0f 100644
--- a/lib/facter/application.rb
+++ b/lib/facter/application.rb
@@ -93,35 +93,80 @@ module Facter
     # @return [Hash] options hash
     def self.parse(argv)
       options = {}
-      OptionParser.new do |opts|
-        opts.on("-y", "--yaml")   { |v| options[:yaml]   = v }
-        opts.on("-j", "--json")   { |v| options[:json]   = v }
-        opts.on(      "--trace")  { |v| options[:trace]  = v }
-        opts.on(      "--external-dir DIR") { |v| create_directory_loader(v) }
-        opts.on(      "--no-external-dir") { |v| create_nothing_loader }
-        opts.on("-d", "--debug")  { |v| Facter.debugging(1) }
-        opts.on("-t", "--timing") { |v| Facter.timing(1) }
-        opts.on("-p", "--puppet") { |v| load_puppet }
-
-        opts.on_tail("-v", "--version") do
+      parser = OptionParser.new do |opts|
+        opts.banner = <<-BANNER
+Synopsis
+========
+
+Collect and display facts about the system.
+
+Usage
+=====
+
+  facter [-d|--debug] [-h|--help] [-p|--puppet] [-v|--version] [-y|--yaml] [-j|--json] [--external-dir DIR] [--no-external-dir] [fact] [fact] [...]
+
+Description
+===========
+
+Collect and display facts about the current system.  The library behind
+Facter is easy to expand, making Facter an easy way to collect information
+about a system from within the shell or within Ruby.
+
+If no facts are specifically asked for, then all facts will be returned.
+
+EXAMPLE
+=======
+  facter kernel
+
+AUTHOR
+======
+  Luke Kanies
+
+COPYRIGHT
+=========
+  Copyright (c) 2011-2012 Puppet Labs, Inc Licensed under the Apache 2.0 license
+
+USAGE
+=====
+        BANNER
+        opts.on("-y",
+                "--yaml",
+                "Emit facts in YAML format.")   { |v| options[:yaml]   = v }
+        opts.on("-j",
+                "--json",
+                "Emit facts in JSON format.")   { |v| options[:json]   = v }
+        opts.on("--trace",
+                "Enable backtraces.")  { |v| options[:trace]  = v }
+        opts.on("--external-dir DIR",
+                "The directory to use for external facts.") { |v| create_directory_loader(v) }
+        opts.on("--no-external-dir",
+                "Turn off external facts.") { |v| create_nothing_loader }
+        opts.on("-d",
+                "--debug",
+                "Enable debugging.")  { |v| Facter.debugging(1) }
+        opts.on("-t",
+                "--timing",
+                "Enable timing.") { |v| Facter.timing(1) }
+        opts.on("-p",
+                "--puppet",
+                "Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.") { |v| load_puppet }
+
+        opts.on_tail("-v",
+                     "--version",
+                     "Print the version and exit.") do
           puts Facter.version
           exit(0)
         end
 
-        opts.on_tail("-h", "--help") do
-          begin
-            require 'rdoc/ri/ri_paths'
-            require 'rdoc/usage'
-            RDoc.usage # print usage and exit
-          rescue LoadError
-            $stderr.puts "No help available unless your RDoc has RDoc.usage"
-            exit(1)
-          rescue => e
-            $stderr.puts "fatal: #{e}"
-            exit(1)
-          end
+        opts.on_tail("-h",
+                     "--help",
+                     "Print this help message.") do
+          puts parser
+          exit(0)
         end
-      end.parse!(argv)
+      end
+
+      parser.parse!(argv)
 
       options
     rescue OptionParser::InvalidOption => e

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list