openstudiocore/src/cli/openstudio_cli.rb
# This method will split the argv given into three parts: the flags to this command, the command, and the flags to
# the command. For example:
#     -v status -h -v
# The above would yield 3 parts:
#     ["-v"]
#     "status"
#     ["-h", "-v"]
# These parts are useful because the first is a list of arguments given to the current command, the second is a
# command, and the third are the commands given to the command
#
# @param [Array] argv The input to be split
# @param [Array] command_list Hash of commands to look for
# @return [Array] The split command as [main arguments, sub command, sub command arguments]
#
This method will split the argv given into three parts: the flags to this command, the command, and the flags to
the command.
This method will split the argv given into three parts : the flags to this command the command and the flags to the command .
def split_main_and_subcommand(argv, command_list)
  main_args   = nil
  sub_command = nil
  sub_args    = []
  commands = []
  command_list.keys.each {|k| commands << k.to_s}
  argv.each_index do |i|
    if commands.index(argv[i])
      main_args   = argv[0, i]
      sub_command = argv[i]
      sub_args    = argv[i+1..-1]
      break
    elsif argv[i].end_with?('.rb')
      main_args   = argv[0, i]
      sub_command = 'execute_ruby_script'
      sub_args    = argv[i..-1]
      break
    end
  end
  main_args = argv.dup if main_args.nil?
  [main_args, sub_command, sub_args]
end
def split_main_and_subcommand ( argv , command_list ) main_args = nil sub_command = nil sub_args = [ ] commands = [ ] command_list . keys . each { | k | commands << k . to_s } argv . each_index do | i | if commands . index ( argv [ i ] ) main_args = argv [ 0 , i ] sub_command = argv [ i ] sub_args = argv [ i + 1 .. - 1 ] break elsif argv [ i ] . end_with? ( '.rb' ) main_args = argv [ 0 , i ] sub_command = 'execute_ruby_script' sub_args = argv [ i .. - 1 ] break end end main_args = argv . dup if main_args . nil? [ main_args , sub_command , sub_args ] end
This method will split the argv given into three parts: the flags to this command, the command, and the flags to
the command.
This method will split the argv given into three parts : the flags to this command the command and the flags to the command .
# Initialize return variables # We split the arguments into two: One set containing any flags before a word, and then the rest. The rest are what # get actually sent on to the command # Handle the case that argv was empty or didn't contain any command
The split command as [main arguments, sub command, sub command arguments]
The split command as [ main arguments sub command sub command arguments ]
Array
argv
<not_specific>
command_list
<not_specific>
<not_specific>
command_list Hash of commands to look for
command_list Hash of commands to look for