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
krates-1.7.11 lib/kontena/cli/master/config/export_command.rb
krates-1.7.10 lib/kontena/cli/master/config/export_command.rb
krates-1.7.9 lib/kontena/cli/master/config/export_command.rb
krates-1.7.8 lib/kontena/cli/master/config/export_command.rb
krates-1.7.7 lib/kontena/cli/master/config/export_command.rb
krates-1.7.6 lib/kontena/cli/master/config/export_command.rb
krates-1.7.5 lib/kontena/cli/master/config/export_command.rb
krates-1.7.4 lib/kontena/cli/master/config/export_command.rb
krates-1.7.3 lib/kontena/cli/master/config/export_command.rb
krates-1.7.2 lib/kontena/cli/master/config/export_command.rb
krates-1.7.1 lib/kontena/cli/master/config/export_command.rb
krates-1.7.0 lib/kontena/cli/master/config/export_command.rb
krates-1.6.9 lib/kontena/cli/master/config/export_command.rb
krates-1.6.8 lib/kontena/cli/master/config/export_command.rb
krates-1.6.7 lib/kontena/cli/master/config/export_command.rb
krates-1.6.6 lib/kontena/cli/master/config/export_command.rb
krates-1.6.5 lib/kontena/cli/master/config/export_command.rb
krates-1.6.4 lib/kontena/cli/master/config/export_command.rb
krates-1.6.3 lib/kontena/cli/master/config/export_command.rb
krates-1.6.2 lib/kontena/cli/master/config/export_command.rb