Sha256: 9c0b70783db635debe0431a4037e7ab78d049ab66e45b6cf795b16283672ae4a

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

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

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

          VagrantPlugins::Openstack::Action::ConnectOpenstack.new(nil, env).call(env)

          cmd(name, @argv, env)
          @env.ui.info('')
        end

        #
        # 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 cmd(_name, _argv, _env)
          fail 'Command not implemented. \'cmd\' method must be overridden in all subclasses'
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-openstack-provider-0.5.2 lib/vagrant-openstack-provider/command/abstract_command.rb
vagrant-openstack-provider-0.5.1 lib/vagrant-openstack-provider/command/abstract_command.rb
vagrant-openstack-provider-0.5.0 lib/vagrant-openstack-provider/command/abstract_command.rb