Sha256: 9a6b5d9a682e5197b44414cf44294e5094ba3fb0135bb6f79501ed1319a30069

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

require_relative 'common'

module Kontena::Cli::Stacks
  class ValidateCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions
    include Common

    banner "Validates a YAML file"

    include Common::StackFileOrNameParam
    include Common::StackNameOption

    include Common::StackValuesToOption
    include Common::StackValuesFromOption

    option '--online', :flag, "Enable connections to current master", default: false

    def execute
      unless online?
        config.current_master = nil
        values ||= {}
        values.merge!('GRID' => 'validate')
      end

      reader = reader_from_yaml(filename, name: name, values: values)
      outcome = reader.execute
      hint_on_validation_notifications(outcome[:notifications]) unless outcome[:notifications].empty?
      abort_on_validation_errors(outcome[:errors]) unless outcome[:errors].empty?

      dump_variables(reader) if values_to

      result = reader.fully_interpolated_yaml.merge(
        # simplest way to stringify keys in a hash
        'variables' => JSON.parse(reader.variables.to_h(with_values: true, with_errors: true).to_json)
      )
      puts ::YAML.dump(result)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
kontena-cli-1.3.0.pre1 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.2 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.2.rc2 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.2.rc1 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.1 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.1.rc1 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.0 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.0.rc3 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.0.rc2 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.0.rc1 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.0.pre3 lib/kontena/cli/stacks/validate_command.rb
kontena-cli-1.2.0.pre2 lib/kontena/cli/stacks/validate_command.rb