fastlane_core 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce6315db355b51ee4d502ab055dbdfe93ef53425
4
- data.tar.gz: d831602adf386b7b227459fb196110d6b4963b50
3
+ metadata.gz: 0b71366adf4b314624463dc2ea6071a1b45fdfaa
4
+ data.tar.gz: d9c384d0df79afa89da41c937372cc9fbbee1989
5
5
  SHA512:
6
- metadata.gz: d86a26d83cb4eb0f372ecfd30a8f84bcab3c535230f1285e1895ddb52dfd1719da81d3333101ed33ced6c609653f0b31b05e4e5277647cb5c1c33853fad12df7
7
- data.tar.gz: 45d8b9ba85e135cd98f276b2e3f8ec0fe89ab3bfd488a85ea037b6cf32deef84462de0e11b8a6f8f318b72adaeda1636f28f81f1e7dd89b92b5e2f3eb3f2604f
6
+ metadata.gz: d641d8f801d277a98e409985206c90690206517a5bd851c11a751da5a9e88ea41c3670d7b1a0a183d5b08c168f52aaa845bfa550288c31ced46faa9604701713
7
+ data.tar.gz: 1486be1a878cadb6385965a19fc9dfe6231811de878ea76b530078945f7e7d137dc65951a4b9588c6cbee97af3b1337f30aa892af5c5e5e2fcdd90f8aade247c
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'fastlane_core/version'
3
3
  require 'fastlane_core/helper'
4
+ require 'fastlane_core/configuration'
4
5
  require 'fastlane_core/update_checker'
5
6
  require 'fastlane_core/languages'
6
7
  require 'fastlane_core/itunes_search_api'
@@ -0,0 +1,108 @@
1
+ require 'fastlane_core/configuration/config_item'
2
+ require 'fastlane_core/configuration/commander_generator'
3
+
4
+ module FastlaneCore
5
+ class Configuration
6
+ def self.create(available_options, values)
7
+ Configuration.new(available_options, values)
8
+ end
9
+
10
+ # Setting up
11
+
12
+ def initialize(available_options, values)
13
+ @available_options = available_options
14
+ @values = values
15
+
16
+ verify_input_types
17
+ verify_value_exists
18
+ verify_no_duplicates
19
+ end
20
+
21
+ def verify_input_types
22
+ raise "available_options parameter must be an array of ConfigItems".red unless @available_options.kind_of?Array
23
+ @available_options.each do |item|
24
+ raise "available_options parameter must be an array of ConfigItems".red unless item.kind_of?ConfigItem
25
+ end
26
+ raise "values parameter must be a hash".red unless @values.kind_of?Hash
27
+ end
28
+
29
+ def verify_value_exists
30
+ # Make sure the given value keys exist
31
+ @values.each do |key, value|
32
+ option = option_for_key(key)
33
+ if option
34
+ option.verify!(value) # Call the verify block for it too
35
+ else
36
+ raise "Could not find available option '#{key}' in the list of available options #{@available_options.collect { |a| a.key }}".red
37
+ end
38
+ end
39
+ end
40
+
41
+ def verify_no_duplicates
42
+ # Make sure a key was not used multiple times
43
+ @available_options.each do |current|
44
+ count = @available_options.select { |option| option.key == current.key }.count
45
+ raise "Multiple entries for configuration key '#{current.key}' found!".red if count > 1
46
+
47
+ unless current.short_option.to_s.empty?
48
+ count = @available_options.select { |option| option.short_option == current.short_option }.count
49
+ raise "Multiple entries for short_option '#{current.short_option}' found!".red if count > 1
50
+ end
51
+ end
52
+ end
53
+
54
+ # Using the class
55
+
56
+ # Returns the value for a certain key. fastlane_core tries to fetch the value from different sources
57
+ def fetch(key)
58
+ raise "Key '#{key}' must be a symbol. Example :app_id.".red unless key.kind_of?Symbol
59
+
60
+ option = option_for_key(key)
61
+ raise "Could not find option for key :#{key}. Available keys: #{@available_options.collect { |a| a.key }}".red unless option
62
+
63
+ # `if value == nil` instead of ||= because false is also a valid value
64
+
65
+ value ||= @values[key]
66
+ # TODO: configuration files
67
+ value = ENV[key.to_s] if value == nil
68
+ value = option.default_value if value == nil
69
+ value = false if (value == nil and not option.is_string) # by default boolean flags are false
70
+
71
+ while value == nil and !option.optional
72
+ value = ask("#{option.description}: ")
73
+ # Also store this value to use it from now on
74
+ begin
75
+ set(key, value)
76
+ rescue Exception => ex
77
+ puts ex
78
+ value = nil
79
+ end
80
+ end
81
+
82
+ value
83
+ end
84
+
85
+ # Overwrites or sets a new value for a given key
86
+ def set(key, value)
87
+ raise "Key '#{key}' must be a symbol. Example :app_id.".red unless key.kind_of?Symbol
88
+ option = option_for_key(key)
89
+
90
+ unless option
91
+ raise "Could not find available option '#{key}' in the list of !available options #{@available_options.collect { |a| a.key }}".red
92
+ end
93
+
94
+ option.verify!(value)
95
+
96
+ @values[key] = value
97
+ true
98
+ end
99
+
100
+ # Returns the config_item object for a given key
101
+ def option_for_key(key)
102
+ @available_options.find { |o| o.key == key }
103
+ end
104
+
105
+ # Aliases `[key]` to `fetch(key)` because Ruby can do it.
106
+ alias_method :[], :fetch
107
+ end
108
+ end
@@ -0,0 +1,16 @@
1
+ require 'commander'
2
+
3
+ module FastlaneCore
4
+ class CommanderGenerator
5
+ include Commander::Methods
6
+
7
+ def generate(options)
8
+ options.each do |option|
9
+ appendix = (option.is_string ? "STRING" : "")
10
+ type = (option.is_string ? String : nil)
11
+ short_option = option.short_option || "-#{option.key.to_s[0]}"
12
+ global_option short_option, "--#{option.key} #{appendix}", type, (option.description + " (#{option.env_name})")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,69 @@
1
+ module FastlaneCore
2
+ class ConfigItem
3
+ attr_accessor :key, :env_name, :description, :short_option, :default_value, :verify_block, :is_string, :optional
4
+
5
+ # Creates a new option
6
+ # @param key (Symbol) the key which is used as command paramters or key in the fastlane tools
7
+ # @param env_name (String) the name of the environment variable, which is only used if no other values were found
8
+ # @param description (String) A description shown to the user
9
+ # @param short_option (String) A string of length 1 which is used for the command parameters (e.g. -f)
10
+ # @param default_value the value which is used if there was no given values and no environment values
11
+ # @param verify_block an optional block which is called when a new value is set.
12
+ # Check value is valid. This could be type checks or if a folder/file exists
13
+ # You have to raise a specific exception if something goes wrong. Append .red after the string
14
+ # @param is_string (String) is that parameter a string?
15
+ # @param optional (Boolean) is false by default. If set to true, also string values will not be asked to the user
16
+ def initialize(key: nil, env_name: nil, description: nil, short_option: nil, default_value: nil, verify_block: nil, is_string: true, optional: false)
17
+ raise "key must be a symbol" unless key.kind_of?Symbol
18
+ raise "env_name must be a String" unless env_name.kind_of?String
19
+ if short_option
20
+ raise "short_option must be a String of length 1" unless (short_option.kind_of?String and short_option.gsub('-', '').length == 1)
21
+ end
22
+ if description
23
+ raise "Do not let descriptions end with a '.', since it's used for user inputs as well".red if (description[-1] == '.')
24
+ end
25
+
26
+ @key = key
27
+ @env_name = env_name
28
+ @description = description
29
+ @short_option = short_option
30
+ @default_value = default_value
31
+ @verify_block = verify_block
32
+ @is_string = is_string
33
+ @optional = optional
34
+ end
35
+
36
+
37
+ # This will raise an exception if the value is not valid
38
+ def verify!(value)
39
+ raise "Invalid value '#{value}' for option '#{self}'".red unless is_valid?value
40
+ true
41
+ end
42
+
43
+ # Make sure, the value is valid (based on the verify block)
44
+ # Returns false if that's not the case
45
+ def is_valid?(value)
46
+ # we also allow nil values, which do not have to be verified.
47
+ if value
48
+ if @is_string
49
+ raise "Please pass a path as String".red unless value.kind_of?String
50
+ end
51
+
52
+ if @verify_block
53
+ begin
54
+ @verify_block.call(value)
55
+ rescue Exception => ex
56
+ Helper.log.fatal "Error setting value '#{value}' for option '#{@key}'".red
57
+ raise ex
58
+ end
59
+ end
60
+ end
61
+
62
+ true
63
+ end
64
+
65
+ def to_s
66
+ [@key, @description].join(": ")
67
+ end
68
+ end
69
+ end
@@ -53,6 +53,12 @@ module FastlaneCore
53
53
  self.test?
54
54
  end
55
55
 
56
+ # @return true if building in a known CI environment
57
+ def self.is_ci?
58
+ # Check for Jenkins or Travis CI environment variables
59
+ ENV.has_key?("JENKINS_URL") || ENV.has_key?("TRAVIS")
60
+ end
61
+
56
62
  # @return the full path to the Xcode developer tools of the currently
57
63
  # running system
58
64
  def self.xcode_path
@@ -1,3 +1,3 @@
1
1
  module FastlaneCore
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-28 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -258,6 +258,9 @@ files:
258
258
  - LICENSE
259
259
  - README.md
260
260
  - lib/fastlane_core.rb
261
+ - lib/fastlane_core/configuration.rb
262
+ - lib/fastlane_core/configuration/commander_generator.rb
263
+ - lib/fastlane_core/configuration/config_item.rb
261
264
  - lib/fastlane_core/developer_center/developer_center.rb
262
265
  - lib/fastlane_core/developer_center/developer_center_helper.rb
263
266
  - lib/fastlane_core/developer_center/developer_center_login.rb
@@ -269,7 +272,7 @@ files:
269
272
  - lib/fastlane_core/languages.rb
270
273
  - lib/fastlane_core/update_checker.rb
271
274
  - lib/fastlane_core/version.rb
272
- homepage: http://fastlane.tools
275
+ homepage: https://fastlane.tools
273
276
  licenses:
274
277
  - MIT
275
278
  metadata: {}