Sha256: 483b76ef20b37c4130a0f1d0315912e5b8a084678177a3efff10be4823c123fa

Contents?: true

Size: 1.89 KB

Versions: 12

Compression:

Stored size: 1.89 KB

Contents

require 'optparse'

module VagrantSnap

    module Command

        class Root < Vagrant.plugin("2", :command)

            def initialize(argv, env)

                super

                @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)

                @subcommands = Vagrant::Registry.new

                @subcommands.register(:take) do
                    require_relative "take"
                    Take
                end

                @subcommands.register(:rollback) do
                    require_relative "rollback"
                    Rollback
                end

                @subcommands.register(:list) do
                    require_relative "list"
                    List
                end


            end

            def execute

                if @main_args.include?("-h") || @main_args.include?("--help")
                    return help
                end

                command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
                return help if !command_class || !@sub_command

                # Initialize and execute the command class
                command_class.new(@sub_args, @env).execute

            end

            def help
                opts = OptionParser.new do |opts|
                    opts.banner = 'Usage: vagrant snap <command> [<args>]'
                    opts.separator ""
                    opts.separator "Available subcommands:"

                    keys = []
                    @subcommands.each { |key, value| keys << key.to_s }

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

                    opts.separator ""
                    opts.separator "For help on any individual command run 'vagrant snap COMMAND -h'"
                end

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

        end

    end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
vagrant-multiprovider-snap-0.0.12 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.11 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.10 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.9 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.8 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.7 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.6 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.5 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-multiprovider-snap-0.0.4 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-zz-multiprovider-snap-0.0.3 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-zz-multiprovider-snap-0.0.2 lib/vagrant-multiprovider-snap/command/root.rb
vagrant-zz-multiprovider-snap-0.0.1 lib/vagrant-multiprovider-snap/command/root.rb