Method: FastlaneCore::ConfigItem#initialize

Defined in:
lib/fastlane_core/configuration/config_item.rb

#initialize(key: nil, env_name: nil, description: nil, short_option: nil, default_value: nil, verify_block: nil, is_string: true, type: nil, optional: nil, conflicting_options: nil, conflict_block: nil, deprecated: nil) ⇒ ConfigItem

Creates a new option

Parameters:

  • key (Symbol) (defaults to: nil)

    the key which is used as command paramters or key in the fastlane tools

  • env_name (String) (defaults to: nil)

    the name of the environment variable, which is only used if no other values were found

  • description (String) (defaults to: nil)

    A description shown to the user

  • short_option (String) (defaults to: nil)

    A string of length 1 which is used for the command parameters (e.g. -f)

  • default_value (defaults to: nil)

    the value which is used if there was no given values and no environment values

  • verify_block (defaults to: nil)

    an optional block which is called when a new value is set. Check value is valid. This could be type checks or if a folder/file exists You have to raise a specific exception if something goes wrong. Append .red after the string

  • is_string (defaults to: true)

    *DEPRECATED: Use ‘type` instead* (Boolean) is that parameter a string? Defaults to true. If it’s true, the type string will be verified.

  • type (Class) (defaults to: nil)

    the data type of this config item. Takes precedence over ‘is_string`

  • optional (Boolean) (defaults to: nil)

    is false by default. If set to true, also string values will not be asked to the user

  • conflicting_options ([]) (defaults to: nil)

    array of conflicting option keys(@param key). This allows to resolve conflicts intelligently

  • conflict_block (defaults to: nil)

    an optional block which is called when options conflict happens

  • deprecated (String) (defaults to: nil)

    Set if the option is deprecated. A deprecated option should be optional and is made optional if the parameter isn’t set, and fails otherwise



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fastlane_core/configuration/config_item.rb', line 20

def initialize(key: nil, env_name: nil, description: nil, short_option: nil, default_value: nil, verify_block: nil, is_string: true, type: nil, optional: nil, conflicting_options: nil, conflict_block: nil, deprecated: nil)
  UI.user_error!("key must be a symbol") unless key.kind_of? Symbol
  UI.user_error!("env_name must be a String") unless (env_name || '').kind_of? String

  if short_option
    UI.user_error!("short_option must be a String of length 1") unless short_option.kind_of? String and short_option.delete('-').length == 1
  end
  if description
    UI.user_error!("Do not let descriptions end with a '.', since it's used for user inputs as well") if description[-1] == '.'
  end

  if conflicting_options
    conflicting_options.each do |conflicting_option_key|
      UI.user_error!("Conflicting option key must be a symbol") unless conflicting_option_key.kind_of? Symbol
    end
  end
  if deprecated
    # deprecated options are automatically optional
    optional = true if optional.nil?
    UI.crash!("Deprecated option must be optional") unless optional
    # deprecated options are marked deprecated in their description
    description = "[DEPRECATED!] #{deprecated} - #{description}"
  end
  optional = false if optional.nil?

  @key = key
  @env_name = env_name
  @description = description
  @short_option = short_option
  @default_value = default_value
  @verify_block = verify_block
  @is_string = is_string
  @data_type = type
  @optional = optional
  @conflicting_options = conflicting_options
  @conflict_block = conflict_block
  @deprecated = deprecated
end