Sha256: 6f58ace11b50b94ee09050b49cecb2261f4e3fbd807fba03d7edf74f971afa5a

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "thor"

require_relative "../session"
require_relative "./constants"

module NeetoDeploy
  class CLI
    module Redis
      class Set < CLI::Base
        include Constants
        include Session

        attr_reader :addon_name, :key, :value

        def initialize(options)
          super()
          @addon_name = options[:addon_name]
          @key = options[:key]
          @value = options[:value]
        end

        def run
          unless valid_config?
            ui.error("Could not set cofig \"#{key}\". Please refer manageable redis configs: #{AVAILABLE_REDIS_CONFIGS_TO_EDIT}")
            return
          end

          ui.execute_with_loading("Setting config...") do
            send_request
          end
          print_output
        end

        private

          def valid_config?
            AVAILABLE_REDIS_CONFIGS_TO_EDIT.include?(key)
          end

          def send_request
            @response = send_patch_request(
              redis_addon_url, {
                addon_name:,
                command: "CONFIG set #{key} #{value}"
              }
            )
          end

          def print_output
            ui.error(@response["error"]) and return unless @response.success?

            ui.success("#{key} config for #{addon_name} set to #{value}")
          end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
neetodeploy-1.1.10 lib/neeto_deploy/cli/redis/set.rb
neetodeploy-1.1.9 lib/neeto_deploy/cli/redis/set.rb
neetodeploy-1.1.8 lib/neeto_deploy/cli/redis/set.rb
neetodeploy-1.1.7 lib/neeto_deploy/cli/redis/set.rb
neetodeploy-1.1.6 lib/neeto_deploy/cli/redis/set.rb