Sha256: 6c88e7cb3c3547a0b023dd52f1b52fa848e3743d9600c866a8b1e8fbf83e0fca

Contents?: true

Size: 1.15 KB

Versions: 153

Compression:

Stored size: 1.15 KB

Contents

module Kontena::Cli::Master::Config
  class ExportCommand < Kontena::Command

    include Kontena::Cli::Common

    requires_current_master
    requires_current_master_token

    banner "Reads configuration from master"

    parameter '[PATH]', "Output to file in PATH, default: STDOUT", required: false
    option ['-f', '--format'], '[FORMAT]', "Specify output format (json, yaml) (default: guess from PATH or json)"

    option ['--filter'], "[FILTER]", "Filter keys, example: oauth2.*"

    def decorate(data)
      case self.format.downcase
      when 'json'
        require 'json'
        JSON.pretty_generate(data)
      when 'yaml', 'yml'
        require 'yaml'
        YAML.dump(data)
      else
        exit_with_error "Unknown output format '#{self.format}'"
      end
    end

    def output(content)
      self.path ? File.write(self.path, content) : puts(content)
    end

    def data
      client.get("config", self.filter ? { filter: self.filter } : nil)
    end

    def set_default_format
      self.format ||= self.path.to_s.end_with?('.yml') ? 'yaml' : 'json'
    end

    def execute
      set_default_format
      output(decorate(data))
    end
  end
end

Version data entries

153 entries across 153 versions & 2 rubygems

Version Path
kontena-cli-1.4.0.pre1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.4 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.4.rc1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.3 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.3.rc1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.2 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.2.rc2 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.2.rc1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.1.rc2 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.1.rc1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.0 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.0.rc4 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.0.rc3 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.0.rc2 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.0.rc1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.0.pre2 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.3.0.pre1 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.2.2 lib/kontena/cli/master/config/export_command.rb
kontena-cli-1.2.2.rc2 lib/kontena/cli/master/config/export_command.rb