Sha256: 64757b98809d5cb0b76d07c9b3edf768884819f1a63531531dca83c85697070d

Contents?: true

Size: 1.14 KB

Versions: 31

Compression:

Stored size: 1.14 KB

Contents

require 'vagrant'

class PEBuild::Command::Base < Vagrant.plugin(2, :command)

  def initialize(argv, env)
    super
    split_argv

    @subcommands = {
      'list'     => PEBuild::Command::List,
      'download' => PEBuild::Command::Download,
      'copy'     => PEBuild::Command::Copy,
    }
  end

  def execute
    if @subcommand
      execute_subcommand
    else
      print_help
    end
  end

  private

  def split_argv
    @main_args, @subcommand, @sub_args = split_main_and_subcommand(@argv)
  end

  def execute_subcommand
    if (klass = @subcommands[@subcommand])
      klass.new(@argv, @env).execute
    else
      raise "Unrecognized subcommand #{@subcommand}"
    end
  end

  def print_help
    cmd = 'vagrant pe-build'
    opts = OptionParser.new do |opts|
      opts.banner = "Usage: #{cmd} <command> [<args>]"
      opts.separator ""
      opts.separator "Available subcommands:"

      @subcommands.keys.sort.each do |key|
        opts.separator "     #{key}"
      end

      opts.separator ""
      opts.separator "For help on any individual command run `#{cmd} COMMAND -h`"
    end

    @env.ui.info(opts.help, :prefix => false)
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
vagrant-pe_build-0.10.4 lib/pe_build/command/base.rb
vagrant-pe_build-0.10.3 lib/pe_build/command/base.rb
vagrant-pe_build-0.10.2 lib/pe_build/command/base.rb
vagrant-pe_build-0.10.1 lib/pe_build/command/base.rb
vagrant-pe_build-0.10.0 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.7 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.6 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.5 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.4 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.3 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.2 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.1 lib/pe_build/command/base.rb
vagrant-pe_build-0.9.0 lib/pe_build/command/base.rb
vagrant-pe_build-0.8.8 lib/pe_build/command/base.rb
vagrant-pe_build-0.8.7 lib/pe_build/command/base.rb
vagrant-pe_build-0.8.6 lib/pe_build/command/base.rb
vagrant-pe_build-0.8.5 lib/pe_build/command/base.rb
vagrant-pe_build-0.8.4 lib/pe_build/command/base.rb
vagrant-pe_build-0.8.3 lib/pe_build/command/base.rb
vagrant-pe_build-0.8.2 lib/pe_build/command/base.rb