src/cli/openstudio_cli.rb
# This is a convenience method that properly handles duping the originally argv array so that it is not destroyed. This
# method will also automatically detect "-h" and "--help" and print help. And if any invalid options are  detected, the
# help will be printed, as well
#
# @param [Object, nil] opts An instance of OptionParse to parse against, defaults to a new OptionParse instance
# @param [Array, nil] argv The argv input to be parsed, defaults to $argv
# @return[Array, nil] If this method returns `nil`, then you should assume that help was printed and parsing failed
#
This is a convenience method that properly handles duping the originally argv array so that it is not destroyed. This
method will also automatically detect "-h" and "--help" and print help. And if any invalid options are  detected, the
help will be printed, as well
This is a convenience method that properly handles duping the originally argv array so that it is not destroyed . This method will also automatically detect " - h " and " -- help " and print help . And if any invalid options are detected the help will be printed as well
def parse_options(opts=nil, argv=nil)
  argv ||= $argv.dup
  opts ||= OptionParser.new
  opts.on_tail('-h', '--help', 'Print this help') do
    safe_puts(opts.help)
    return nil
  end
  opts.parse!(argv)
  return argv
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
  raise "Error: Invalid CLI option, #{opts.help.chomp}"
end
def parse_options ( opts = nil , argv = nil ) argv ||= $argv . dup opts ||= OptionParser . new opts . on_tail ( '-h' , '--help' , 'Print this help' ) do safe_puts ( opts . help ) return nil end opts . parse! ( argv ) return argv rescue OptionParser :: InvalidOption , OptionParser :: MissingArgument raise "Error: Invalid CLI option, #{opts.help.chomp}" end
This is a convenience method that properly handles duping the originally argv array so that it is not destroyed.
This is a convenience method that properly handles duping the originally argv array so that it is not destroyed .
# Creating a shallow copy of the arguments so the OptionParser # doesn't destroy the originals. # Default opts to a blank optionparser if none is given # Add the help option, which must be on every command.
opts
<not_specific>
argv
<not_specific>
<not_specific>
argv The argv input to be parsed, defaults to $argv
argv The argv input to be parsed defaults to $argv
$argv
return[Array,
nil] If this method returns `nil`, then you should assume that help was printed and parsing failed
nil ] If this method returns ` nil ` then you should assume that help was printed and parsing failed