Ruby "OptionParser will automatically generate help screens for you from this description" [http://ruby.about.com/od/advancedruby/a/optionparser.htm]
Is there a way to remove the help text for a command option. I can use a hidden command, but rather having a command option (switch) and hide its help context.
I was able to throw together a not-so-elegant solution to this. It will hide the option from the main help screen, it sounds like it might fit your needs:
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
opts.on("-a", "--argument 1,2,3", Array, "Array of arguments") { |a| options[:array] = a }
opts.on("-v", "--verbose", "Verbose output") { |v| options[:verbose] = true }
opts.on("-h", "--help", "Display this help") do
hidden_switch = "--argument"
#Typecast opts to a string, split into an array of lines, delete the line
#if it contains the argument, and then rejoins them into a string
puts opts.to_s.split("\n").delete_if { |line| line =~ /#{hidden_switch}/ }.join("\n")
exit
end
end
If you were to run the --help, you would see this output:
Usage: test.rb [options]
-v, --verbose Verbose output
-h, --help Display this help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With