Sha256: 9d0cfd060967e390f12d0364736000456e8cb8646049d7ee86e119a86c17ff18

Contents?: true

Size: 1.33 KB

Versions: 25

Compression:

Stored size: 1.33 KB

Contents

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

        def self.command
          Cri::Command.define do
            name        'rename'
            usage       'rename <old_name> <new_name>'
            summary     'remote rename'
            description 'Rename remote name'
            param       :remote_old_name
            param       :remote_new_name
            runner RemoteRenameSubcommand
          end
        end

        def run
          # 'arguments' cannot be converted to Hash
          rename_remote arguments[:remote_old_name], arguments[:remote_new_name]
        end

        private

        def validate_remote_old_name(name)
          raise ThreeScaleToolbox::Error, "Could not rename, old name '#{name}' does not exist." unless remotes.all.key?(name)
        end

        def validate_remote_new_name(name)
          raise ThreeScaleToolbox::Error, "Could not rename, new name '#{name}' already exists." if remotes.all.key?(name)
        end

        def rename_remote(remote_old_name, remote_new_name)
          validate_remote_old_name remote_old_name
          validate_remote_new_name remote_new_name
          remotes.add(remote_new_name, remotes.delete(remote_old_name))
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

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