Sha256: 97d9e5949a66bc90e7f923faaf7d4ebc8546d8f0b4e7d7db92462fbc06bf7be0

Contents?: true

Size: 1.86 KB

Versions: 37

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

module Bolt
  class PAL
    class YamlPlan
      class Step
        class Script < Step
          def self.allowed_keys
            super + Set['arguments', 'pwsh_params']
          end

          def self.option_keys
            Set['catch_errors', 'env_vars', 'run_as']
          end

          def self.required_keys
            Set['script', 'targets']
          end

          def self.validate_step_keys(body, number)
            super

            if body.key?('arguments') && !body['arguments'].nil? && !body['arguments'].is_a?(Array)
              raise StepError.new('arguments key must be an array', body['name'], number)
            end

            if body.key?('pwsh_params') && !body['pwsh_params'].nil? && !body['pwsh_params'].is_a?(Hash)
              raise StepError.new('pwsh_params key must be a hash', body['name'], number)
            end

            if body.key?('env_vars') && ![Hash, String].include?(body['env_vars'].class)
              raise StepError.new('env_vars key must be a hash or evaluable string', body['name'], number)
            end
          end

          # Returns an array of arguments to pass to the step's function call
          #
          private def format_args(body)
            args        = body['arguments'] || []
            pwsh_params = body['pwsh_params'] || {}

            opts = format_options(body)
            opts = opts.merge('arguments' => args) if args.any?
            opts = opts.merge('pwsh_params' => pwsh_params) if pwsh_params.any?

            args = [body['script'], body['targets']]
            args << body['description'] if body['description']
            args << opts if opts.any?

            args
          end

          # Returns the function corresponding to the step
          #
          private def function
            'run_script'
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
bolt-3.29.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.28.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.27.4 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.27.2 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.27.1 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.26.2 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.26.1 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.25.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.24.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.23.1 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.23.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.22.1 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.22.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.21.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.20.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.19.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.18.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.17.0 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.16.1 lib/bolt/pal/yaml_plan/step/script.rb
bolt-3.16.0 lib/bolt/pal/yaml_plan/step/script.rb