Method: Conify::Command#valid_args?

Defined in:
lib/conify/command.rb

#valid_args?(accepted_arg_formats) ⇒ Boolean

Check if passed-in arguments are valid for a specific format

Returns:

  • (Boolean)


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/conify/command.rb', line 128

def valid_args?(accepted_arg_formats)
  valid_args = false

  accepted_arg_formats.each { |format|
    # if no arguments exist, and no arguments is an accepted format, args are valid.
    if format.empty? && @current_args.empty?
      valid_args = true
    else
      passed_in_args = @current_args.clone

      format.each_with_index { |arg, i|
        passed_in_args[i] = arg if CMD_BLACKLIST.include?(arg)
      }

      @invalid_args = passed_in_args - format - [nil]

      valid_args = true if passed_in_args == format
    end
  }

  valid_args
end