Sha256: f5b90adc995f342bff059e6794a84c91b103c343a70132fc0b7573f8444b14fa

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

require 'shellwords'

module Aptible
  module CLI
    module Subcommands
      module Config
        # rubocop:disable MethodLength
        # rubocop:disable CyclomaticComplexity
        def self.included(thor)
          thor.class_eval do
            include Helpers::Operation
            include Helpers::App

            desc 'config', "Print an app's current configuration"
            option :app
            def config
              app = ensure_app(options)
              config = app.current_configuration
              env = config ? config.env : nil
              puts formatted_config(env || {})
            end

            desc 'config:add', 'Add an ENV variable to an app'
            option :app
            define_method 'config:add' do |*args|
              # FIXME: define_method - ?! Seriously, WTF Thor.
              app = ensure_app(options)
              env = Hash[args.map { |arg| arg.split('=', 2) }]
              operation = app.create_operation(type: 'configure', env: env)
              puts 'Updating configuration and restarting app...'
              poll_for_success(operation)
            end

            desc 'config:rm', 'Remove an ENV variable from an app'
            option :app
            define_method 'config:rm' do |*args|
              # FIXME: define_method - ?! Seriously, WTF Thor.
              app = ensure_app(options)
              env = Hash[args.map { |arg| [arg, ''] }]
              operation = app.create_operation(type: 'configure', env: env)
              puts 'Updating configuration and restarting app...'
              poll_for_success(operation)
            end

            private

            def formatted_config(env)
              env.map { |k, v| "#{k}=#{Shellwords.escape(v)}" }.join("\n")
            end
          end
        end
        # rubocop:enable CyclomaticComplexity
        # rubocop:enable MethodLength
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aptible-cli-0.4.0 lib/aptible/cli/subcommands/config.rb
aptible-cli-0.3.7 lib/aptible/cli/subcommands/config.rb