Method: ReactNativeUtil::Util#validate_commands!
- Defined in:
- lib/react_native_util/util.rb
#validate_commands!(commands) ⇒ Object
Validate one or more commands. If the specified command is not available in the PATH (via which), a ConversionError is raised noting the package to be installed (from Homebrew, e.g.).
When package names to be installed differ from command names, a Hash may be used. For example:
validate_commands! [:yarn, 'react-native' => 'react-native-cli']
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/react_native_util/util.rb', line 120 def validate_commands!(commands) errors = [] case commands when Array # Validate each command in the array, accumulating error messages # if necessary. commands.each do |c| begin validate_commands! c rescue ConversionError => e errors += e..split("\n") end end when Hash # Each key represents a command to check. The value is the package to # install if missing. commands.each do |key, value| next if have_command?(key) errors << "#{key} command not found. Please install #{value} to continue." end else # commands is a single command to be validated. The package name is the # same. Usually a symbol or a string, but only has to respond to #to_s. errors << "#{commands} command not found. Please install #{commands} to continue." unless have_command? commands end return if errors.empty? raise ConversionError, errors.join("\n") end |