Method: PDK::Validate::ExternalCommandValidator#prepare_invoke!

Defined in:
lib/pdk/validate/external_command_validator.rb

#prepare_invoke!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Prepares for invokation by parsing targets and creating the needed commands.

See Also:

  • Validator.prepare_invoke!


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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/pdk/validate/external_command_validator.rb', line 122

def prepare_invoke!
  return if @prepared
  super

  @targets, @skipped, @invalid = parse_targets
  @targets = [] if @targets.nil?

  target_groups = if @targets.empty? && allow_empty_targets?
                    # If we have no targets and we allow empty targets, create an empty target group list
                    [[]]
                  elsif invoke_style == :per_target
                    # If invoking :per_target, split the targets array into an array of
                    # single element arrays (one per target).
                    @targets.combination(1).to_a.compact
                  else
                    # Else we're invoking :once, wrap the targets array in another array. This is so we
                    # can loop through the invokes with the same logic, regardless of which invoke style
                    # is needed.
                    @targets.each_slice(1000).to_a.compact
                  end

  # Register all of the commands for all of the targets
  @commands = []
  target_groups.each do |invokation_targets|
    next if invokation_targets.empty? && !allow_empty_targets?
    cmd_argv = parse_options(invokation_targets).unshift(cmd_path).compact
    cmd_argv.unshift(File.join(PDK::Util::RubyVersion.bin_path, 'ruby.exe'), '-W0') if Gem.win_platform?

    command = PDK::CLI::Exec::Command.new(*cmd_argv).tap do |c|
      c.context = :module
      c.environment = { 'PUPPET_GEM_VERSION' => options[:puppet] } if options[:puppet]

      if spinners_enabled?
        parent_validator = options[:parent_validator]
        if parent_validator.nil? || parent_validator.spinner.nil? || !parent_validator.spinner.is_a?(TTY::Spinner::Multi)
          c.add_spinner(spinner_text_for_targets(invokation_targets))
        else
          spinner = TTY::Spinner.new("[:spinner] #{spinner_text_for_targets(invokation_targets)}", PDK::CLI::Util.spinner_opts_for_platform)
          parent_validator.spinner.register(spinner)
          c.register_spinner(spinner, PDK::CLI::Util.spinner_opts_for_platform)
        end
      end
    end

    @commands << { command: command, invokation_targets: invokation_targets }
  end
  nil
end