Sha256: 8ef20c362b75d6277983585fd30e5e352aa533428246f3803ffcd2b28745acb8

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

module VagrantPlugins
  module CommandServe
    class Type
      class CommandInfo < Type
        class Flag
          TYPES = [:BOOL, :STRING].freeze

          attr_reader :long_name,
            :short_name,
            :default_value,
            :type,
            :description

          def initialize(long_name:, short_name: nil, type:, description: nil)
            @long_name = long_name
            @short_name = short_name
            @description = description
            raise TypeError,
              "Invalid type provided for flag `#{type}'" if !TYPES.include?(type)
            @type = type
          end
        end

        attr_reader :name,
          :help,
          :synopsis,
          :flags,
          :subcommands,
          :primary

        def initialize(name:, help:, synopsis: nil, subcommands: [], primary:)
          @name = name.to_s
          @help = help.to_s
          @synopsis = synopsis.to_s
          @subcommands = Array(subcommands)
          @flags = []
          @primary = primary
        end

        def add_flag(**kwargs)
          @flags << Flag.new(**kwargs)
        end

        def add_subcommand(cmd)
          if !cmd.is_a?(CommandInfo)
            raise TypeError,
              "Expected type `#{CommandInfo.name}' but received `#{cmd.class}'"
          end
          @subcommands << cmd
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/commands/serve/type/command_info.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/commands/serve/type/command_info.rb
vagrant-unbundled-2.3.3.0 plugins/commands/serve/type/command_info.rb
vagrant-unbundled-2.3.2.0 plugins/commands/serve/type/command_info.rb