Module: PactBroker::Client::CLI::EnvironmentCommands

Included in:
Broker
Defined in:
lib/pact_broker/client/cli/environment_commands.rb

Constant Summary collapse

ENVIRONMENT_PARAM_NAMES =
[:name, :display_name, :production, :contact_name, :contact_email_address]

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pact_broker/client/cli/environment_commands.rb', line 7

def self.included(thor)
  thor.class_eval do
    def self.shared_environment_options(name_required: false)
      method_option :name, required: name_required, desc: "The uniquely identifying name of the environment as used in deployment code"
      method_option :display_name, desc: "The display name of the environment"
      method_option :production, type: :boolean, default: false, desc: "Whether or not this environment is a production environment. This is currently informational only."
      method_option :contact_name, required: false, desc: "The name of the team/person responsible for this environment"
      method_option :contact_email_address, required: false, desc: "The email address of the team/person responsible for this environment"
      output_option_json_or_text
    end

    desc "create-environment", "Create an environment resource in the Pact Broker to represent a real world deployment or release environment."
    shared_environment_options(name_required: true)
    shared_authentication_options
    def create_environment
      execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES), "CreateEnvironment")
    end

    desc "update-environment", "Update an environment resource in the Pact Broker."
    method_option :uuid, required: true, desc: "The UUID of the environment to update"
    shared_environment_options(name_required: false)
    shared_authentication_options
    def update_environment
      execute_environment_command(params_from_options(ENVIRONMENT_PARAM_NAMES + [:uuid]), "UpdateEnvironment")
    end

    desc "describe-environment", "Describe an environment"
    method_option :uuid, required: true, desc: "The UUID of the environment to describe"
    method_option :output, aliases: "-o", desc: "json or text", default: 'text'
    shared_authentication_options
    def describe_environment
      execute_environment_command(params_from_options([:uuid]), "DescribeEnvironment")
    end

    desc "list-environments", "List environments"
    method_option :output, aliases: "-o", desc: "json or text", default: 'text'
    shared_authentication_options
    def list_environments
      execute_environment_command({}, "ListEnvironments")
    end

    desc "delete-environment", "Delete an environment"
    method_option :uuid, required: true, desc: "The UUID of the environment to delete"
    method_option :output, aliases: "-o", desc: "json or text", default: 'text'
    shared_authentication_options
    def delete_environment
      execute_environment_command(params_from_options([:uuid]), "DeleteEnvironment")
    end

    no_commands do
      def execute_environment_command(params, command_class_name)
        require 'pact_broker/client/environments'
        command_options = { verbose: options.verbose, output: options.output }
        result = PactBroker::Client::Environments.const_get(command_class_name).call(params, command_options, pact_broker_client_options)
        $stdout.puts result.message
        exit(1) unless result.success
      end
    end
  end
end