Class: Fastlane::Actions::SourceEnvFromFileAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



44
45
46
# File 'lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb', line 44

def self.authors
  ["xiongzenghui"]
end

.available_optionsObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb', line 52

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :filepath,
      description: "filepath for env key=value file",
      verify_block: proc do |value|
        UI.user_error!("No filepath given") unless (value and not value.empty?)
        UI.error("file not exist: #{value}") unless File.exist?(value)
      end
    )
  ]
end

.descriptionObject



40
41
42
# File 'lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb', line 40

def self.description
  "set ENV['key']=value from file like key=value"
end

.detailsObject



48
49
50
# File 'lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb', line 48

def self.details
  "set ENV['key']=value from file like key=value"
end

.example_codeObject



69
70
71
72
73
74
# File 'lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb', line 69

def self.example_code
  [
    'source_env_from_file(filepath: "/Users/xiongzenghui/Desktop/env_data")
    pp ENV["XXX"]'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb', line 65

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fastlane/plugin/source_env_from_file/actions/source_env_from_file_action.rb', line 7

def self.run(params)
  filepath = params[:filepath]

  IO.foreach(filepath) {|line|
    aline = line.gsub('export', '')
    # UI.important "aline: #{aline}"

    # key='value'
    mach_result = /(.*)=\"(.*)\"/.match(aline)
    
    # key=value
    unless mach_result
      mach_result = /(.*)=(.*)/.match(aline)
    end
    
    # key=value
    unless mach_result
      mach_result = /(.*)=(.*)/.match(aline)
    end
    next unless mach_result

    key = mach_result[1]
    value = mach_result[2]

    if key && value
      key.strip!
      value.strip!
      # UI.important "#{key}=#{value}"
      ENV[key] = value
    end
  }
end