Sha256: be939ee62dba9d3a1184fb6cd5575832fc0d838a9fd189af6ead332304cd696c

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

module ThreeScaleToolbox
  module Commands
    module RemoteCommand
      class RemoteAddSubcommand < Cri::CommandRunner
        include ThreeScaleToolbox::Command

        def self.command
          Cri::Command.define do
            name        'add'
            usage       'add <name> <url>'
            summary     'remote add'
            description 'Add new remote to the list'
            param       :remote_name
            param       :remote_url
            runner RemoteAddSubcommand
          end
        end

        def run
          # 'arguments' cannot be converted to Hash
          add_remote arguments[:remote_name], arguments[:remote_url]
        end

        private

        def validate_remote_name(name)
          raise ThreeScaleToolbox::Error, 'remote name already exists.' if remotes.all.key?(name)
        end

        def validate_remote(remote_url_str)
          # parsing url before trying to create client
          # raises Invalid URL when syntax is incorrect
          ThreeScaleToolbox::Helper.parse_uri(remote_url_str)
          threescale_client(remote_url_str).list_accounts
        rescue ThreeScale::API::HttpClient::ForbiddenError
          raise ThreeScaleToolbox::Error, 'remote not valid'
        end

        def add_remote(remote_name, remote_url)
          validate_remote_name remote_name
          validate_remote remote_url
          remotes.add_uri(remote_name, remote_url)
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb
3scale_toolbox-0.10.0 lib/3scale_toolbox/commands/remote_command/remote_add.rb