Permalink
Browse files

Merge pull request #522 from zaphod42/issue/stable/help-on-1.9.3

(#15586) Use OptionParser for help
  • Loading branch information...
jpartlow committed Aug 28, 2013
2 parents 9e79d7c + 132c0ce commit ae881a6c32953550fa536aeae12b9a2a5a95d23d
Showing with 69 additions and 82 deletions.
  1. +0 −58 bin/facter
  2. +69 −24 lib/facter/application.rb
View
@@ -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
View
@@ -93,35 +93,80 @@ def self.run(argv)
# @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

0 comments on commit ae881a6

Please sign in to comment.