Sha256: ff9c5b015d8bf0562bd0b77fd7eccdb3dde688aa9a85f768470719833723b7cd

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'vagrant-openstack-illuin-provider/client/openstack'
require 'colorize'

module VagrantPlugins
  module Openstack
    module Command
      class AbstractCommand < Vagrant.plugin('2', :command)
        def initialize(argv, env)
          @env = env
          super(normalize_args(argv), env)
        end

        def execute(name)
          env = {}
          with_target_vms(nil, provider: :openstack) do |machine|
            env[:machine] = machine
            env[:ui] = @env.ui
          end

          before_cmd(name, @argv, env)

          cmd(name, @argv, env)
          @env.ui.info('')
        # rubocop:disable Lint/RescueException
        rescue Errors::VagrantOpenstackError, SystemExit, Interrupt => e
          raise e
        rescue Exception => e
          puts I18n.t('vagrant_openstack.global_error').red unless e.message && e.message.start_with?('Catched Error:')
          raise e
        end
        # rubocop:enable Lint/RescueException

        #
        # Before Vagrant 1.5, args list ends with an extra arg '--'. It removes it if present.
        #
        def normalize_args(args)
          return args if args.nil?
          args.pop if args.size > 0 && args.last == '--'
          args
        end

        def before_cmd(_name, _argv, _env)
        end

        def cmd(_name, _argv, _env)
          fail 'Command not implemented. \'cmd\' method must be overridden in all subclasses'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-openstack-illuin-provider-0.12.0 lib/vagrant-openstack-illuin-provider/command/abstract_command.rb