Method: FastlaneCore::ConfigItem#initialize

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

#initialize(key: nil, env_name: nil, env_names: nil, description: nil, short_option: nil, default_value: nil, default_value_dynamic: false, verify_block: nil, is_string: true, type: nil, skip_type_validation: false, optional: nil, conflicting_options: nil, conflict_block: nil, deprecated: nil, sensitive: nil, code_gen_sensitive: false, code_gen_default_value: nil, display_in_shell: true) ⇒ ConfigItem

Creates a new option rubocop:disable Metrics/ParameterLists rubocop:disable Metrics/PerceivedComplexity

Parameters:

  • key (Symbol) (defaults to: nil)

    the key which is used as command parameters 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

  • env_names (Array) (defaults to: nil)

    the names of the environment variables, 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

  • default_value_dynamic (Boolean) (defaults to: false)

    Set if the default value is generated dynamically

  • 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`. Use `:shell_string` to allow types `String`, `Hash` and `Array` that will be converted to shell-escaped strings

  • skip_type_validation (Boolean) (defaults to: false)

    is false by default. If set to true, type of the parameter will not be validated.

  • 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 (Boolean|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

  • sensitive (Boolean) (defaults to: nil)

    Set if the variable is sensitive, such as a password or API token, to prevent echoing when prompted for the parameter

  • display_in_shell (Boolean) (defaults to: true)

    Set if the variable can be used from shell



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'fastlane_core/lib/fastlane_core/configuration/config_item.rb', line 96

def initialize(key: nil,
               env_name: nil,
               env_names: nil,
               description: nil,
               short_option: nil,
               default_value: nil,
               default_value_dynamic: false,
               verify_block: nil,
               is_string: true,
               type: nil,
               skip_type_validation: false,
               optional: nil,
               conflicting_options: nil,
               conflict_block: nil,
               deprecated: nil,
               sensitive: nil,
               code_gen_sensitive: false,
               code_gen_default_value: nil,
               display_in_shell: true)
  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)

  UI.user_error!("env_names must be an Array") unless (env_names || []).kind_of?(Array)
  (env_names || []).each do |name|
    UI.user_error!("env_names must only contain String") unless (name || '').kind_of?(String)
  end

  if short_option
    UI.user_error!("short_option for key :#{key} must of type String") unless short_option.kind_of?(String)
    UI.user_error!("short_option for key :#{key} must be a string of length 1") unless 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 for key :#{key}") 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_description(description, deprecated)
  end

  optional = false if optional.nil?
  sensitive = false if sensitive.nil?

  @key = key
  @env_name = env_name
  @env_names = [env_name].compact + (env_names || [])
  @description = description
  @short_option = short_option
  @default_value = default_value
  @default_value_dynamic = default_value_dynamic
  @verify_block = verify_block
  @is_string = is_string
  @data_type = type
  @data_type = String if type == :shell_string
  @optional = optional
  @conflicting_options = conflicting_options
  @conflict_block = conflict_block
  @deprecated = deprecated
  @sensitive = sensitive
  @code_gen_sensitive = code_gen_sensitive || sensitive
  @allow_shell_conversion = (type == :shell_string)
  @display_in_shell = display_in_shell
  @skip_type_validation = skip_type_validation # sometimes we allow multiple types which causes type validation failures, e.g.: export_options in gym

  @code_gen_default_value = code_gen_default_value

  update_code_gen_default_value_if_able!
end