Class: Mixlib::Install::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlib/install/options.rb

Defined Under Namespace

Classes: InvalidOptions

Constant Summary collapse

SUPPORTED_ARCHITECTURES =
%w{
  aarch64
  arm64
  armv7l
  i386
  powerpc
  ppc64
  ppc64le
  s390x
  sparc
  x86_64
}
SUPPORTED_CHANNELS =
[
  :stable,
  :current,
  :unstable,
]
SUPPORTED_PRODUCT_NAMES =
PRODUCT_MATRIX.products
SUPPORTED_SHELL_TYPES =
[
  :ps1,
  :sh,
]
SUPPORTED_OPTIONS =
[
  :architecture,
  :channel,
  :platform,
  :platform_version,
  :product_name,
  :product_version,
  :shell_type,
  :platform_version_compatibility_mode,
  :include_metadata,
  :user_agent_headers,
  :install_command_options,
]
SUPPORTED_WINDOWS_DESKTOP_VERSIONS =
%w{10}
SUPPORTED_WINDOWS_NANO_VERSIONS =
%w{2016nano}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Options

Returns a new instance of Options.



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/mixlib/install/options.rb', line 74

def initialize(options)
  @options = options
  @errors = []

  # Store original options in cases where we must remap
  @original_platform_version = options[:platform_version]

  resolve_platform_version_compatibility_mode!

  map_windows_versions!

  validate!
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



29
30
31
# File 'lib/mixlib/install/options.rb', line 29

def errors
  @errors
end

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/mixlib/install/options.rb', line 29

def options
  @options
end

#original_platform_versionObject (readonly)

Returns the value of attribute original_platform_version.



29
30
31
# File 'lib/mixlib/install/options.rb', line 29

def original_platform_version
  @original_platform_version
end

Instance Method Details

#for_ps1?Boolean Also known as: for_windows?

Returns:

  • (Boolean)


109
110
111
# File 'lib/mixlib/install/options.rb', line 109

def for_ps1?
  platform == "windows" || shell_type == :ps1
end

#include_metadata?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/mixlib/install/options.rb', line 132

def include_metadata?
  .to_s == "true"
end

#latest_version?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/mixlib/install/options.rb', line 114

def latest_version?
  product_version.to_sym == :latest
end

#partial_version?Boolean

Returns:

  • (Boolean)


118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/mixlib/install/options.rb', line 118

def partial_version?
  # If PartialSemVer is defined than the version of mixlib-versioning loaded can parse partial versions
  # Otherwise parsing a partial version will return nil
  is_partial = if defined?(Mixlib::Versioning::Format::PartialSemVer)
                 # remove if there's a trailing period for mixlib-versioning compatibility
                 options[:product_version] = product_version.chomp(".") if product_version.is_a? String
                 Mixlib::Versioning.parse(product_version).is_a?(Mixlib::Versioning::Format::PartialSemVer)
               else
                 !Mixlib::Versioning.parse(product_version)
               end

  !latest_version? && is_partial
end

#platform_infoObject



149
150
151
152
153
154
155
# File 'lib/mixlib/install/options.rb', line 149

def platform_info
  {
    platform: options[:platform],
    platform_version: options[:platform_version],
    architecture: options[:architecture],
  }
end

#resolve_platform_version_compatibility_mode!Object

Calling this method will give queries more of an opportunity to collect compatible artifacts where there may not always be an exact match.

This option is set to false by default.

  • In cases where no platform options are configured it will set this option to true.

  • In cases where all platform options are configured it will remain false UNLESS the option has been configured to be true.



166
167
168
169
170
# File 'lib/mixlib/install/options.rb', line 166

def resolve_platform_version_compatibility_mode!
  unless options[:platform_version_compatibility_mode]
    options[:platform_version_compatibility_mode] = true if platform_info.values.none?
  end
end

#set_platform_info(info) ⇒ Object

Set the platform info on the instance info [Hash]

Hash with keys :platform, :platform_version and :architecture


141
142
143
144
145
146
147
# File 'lib/mixlib/install/options.rb', line 141

def set_platform_info(info)
  options[:platform] = info[:platform]
  options[:platform_version] = info[:platform_version]
  options[:architecture] = info[:architecture]

  validate_options!
end

#validate!Object



94
95
96
# File 'lib/mixlib/install/options.rb', line 94

def validate!
  validate_options!
end

#validate_options!Object

Raises:



98
99
100
101
102
103
104
105
106
107
# File 'lib/mixlib/install/options.rb', line 98

def validate_options!
  validate_architecture
  validate_product_names
  validate_channels
  validate_shell_type
  validate_user_agent_headers
  validate_platform_options

  raise InvalidOptions, errors.join("\n") unless errors.empty?
end