Class: Match::CommandsGenerator

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
match/lib/match/commands_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



25
26
27
# File 'match/lib/match/commands_generator.rb', line 25

def self.start
  self.new.run
end

Instance Method Details

#runObject



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'match/lib/match/commands_generator.rb', line 29

def run
  program :name, 'match'
  program :version, Fastlane::VERSION
  program :description, Match::DESCRIPTION
  program :help, 'Author', 'Felix Krause <[email protected]>'
  program :help, 'Website', 'https://fastlane.tools'
  program :help, 'Documentation', 'https://docs.fastlane.tools/actions/match/'
  program :help_formatter, FastlaneCore::HelpFormatter

  global_option('--verbose') { FastlaneCore::Globals.verbose = true }
  global_option('--env STRING[,STRING2]', String, 'Add environment(s) to use with `dotenv`')

  command :run do |c|
    c.syntax = 'fastlane match'
    c.description = Match::DESCRIPTION

    FastlaneCore::CommanderGenerator.new.generate(Match::Options.available_options, command: c)

    c.action do |args, options|
      if args.count > 0
        FastlaneCore::UI.user_error!("Please run `fastlane match [type]`, allowed values: development, adhoc, enterprise  or appstore")
      end

      params = FastlaneCore::Configuration.create(Match::Options.available_options, options.__hash__)
      params.load_configuration_file("Matchfile")
      Match::Runner.new.run(params)
    end
  end

  Match.environments.each do |type|
    command type do |c|
      c.syntax = "fastlane match #{type}"
      c.description = "Run match for a #{type} provisioning profile"

      FastlaneCore::CommanderGenerator.new.generate(Match::Options.available_options, command: c)

      c.action do |args, options|
        params = FastlaneCore::Configuration.create(Match::Options.available_options, options.__hash__)
        params.load_configuration_file("Matchfile") # this has to be done *before* overwriting the value
        params[:type] = type.to_s
        Match::Runner.new.run(params)
      end
    end
  end

  command :init do |c|
    c.syntax = 'fastlane match init'
    c.description = 'Create the Matchfile for you'
    c.action do |args, options|
      containing = FastlaneCore::Helper.fastlane_enabled_folder_path
      is_swift_fastfile = args.include?("swift")

      if is_swift_fastfile
        path = File.join(containing, "Matchfile.swift")
      else
        path = File.join(containing, "Matchfile")
      end

      if File.exist?(path)
        FastlaneCore::UI.user_error!("You already have a Matchfile in this directory (#{path})")
        return 0
      end

      Match::Setup.new.run(path, is_swift_fastfile: is_swift_fastfile)
    end
  end

  command :change_password do |c|
    c.syntax = 'fastlane match change_password'
    c.description = 'Re-encrypt all files with a different password'

    FastlaneCore::CommanderGenerator.new.generate(Match::Options.available_options, command: c)

    c.action do |args, options|
      params = FastlaneCore::Configuration.create(Match::Options.available_options, options.__hash__)
      params.load_configuration_file("Matchfile")

      Match::ChangePassword.update(params: params)
      UI.success("Successfully changed the password. Make sure to update the password on all your clients and servers by running `fastlane match [environment]`")
    end
  end

  command :decrypt do |c|
    c.syntax = "fastlane match decrypt"
    c.description = "Decrypts the repository and keeps it on the filesystem"

    FastlaneCore::CommanderGenerator.new.generate(Match::Options.available_options, command: c)

    c.action do |args, options|
      params = FastlaneCore::Configuration.create(Match::Options.available_options, options.__hash__)
      params.load_configuration_file("Matchfile")

      storage = Storage.from_params(params)
      storage.download

      encryption = Encryption.for_storage_mode(params[:storage_mode], {
        git_url: params[:git_url],
        s3_bucket: params[:s3_bucket],
        s3_skip_encryption: params[:s3_skip_encryption],
        working_directory: storage.working_directory
      })
      encryption.decrypt_files if encryption
      UI.success("Repo is at: '#{storage.working_directory}'")
    end
  end

  command :import do |c|
    c.syntax = "fastlane match import"
    c.description = "Imports certificates and profiles into the encrypted repository"

    FastlaneCore::CommanderGenerator.new.generate(Match::Options.available_options, command: c)

    c.action do |args, options|
      params = FastlaneCore::Configuration.create(Match::Options.available_options, options.__hash__)
      params.load_configuration_file("Matchfile") # this has to be done *before* overwriting the value
      Match::Importer.new.import_cert(params)
    end
  end

  command :migrate do |c|
    c.syntax = "fastlane match migrate"
    c.description = "Migrate from one storage backend to another one"

    FastlaneCore::CommanderGenerator.new.generate(Match::Options.available_options, command: c)

    c.action do |args, options|
      params = FastlaneCore::Configuration.create(Match::Options.available_options, options.__hash__)
      Match::Migrate.new.migrate(params)
    end
  end

  command "nuke" do |c|
    # We have this empty command here, since otherwise the normal `match` command will be executed
    c.syntax = "fastlane match nuke"
    c.description = "Delete all certificates and provisioning profiles from the Apple Dev Portal"
    c.action do |args, options|
      FastlaneCore::UI.user_error!("Please run `fastlane match nuke [type], allowed values: development, distribution and enterprise. For the 'adhoc' type, please use 'distribution' instead.")
    end
  end

  ["development", "distribution", "enterprise"].each do |type|
    command "nuke #{type}" do |c|
      c.syntax = "fastlane match nuke #{type}"
      c.description = "Delete all certificates and provisioning profiles from the Apple Dev Portal of the type #{type}"

      FastlaneCore::CommanderGenerator.new.generate(Match::Options.available_options, command: c)

      c.action do |args, options|
        params = FastlaneCore::Configuration.create(Match::Options.available_options, options.__hash__)
        params.load_configuration_file("Matchfile")
        Match::Nuke.new.run(params, type: type.to_s)
      end
    end
  end

  default_command(:run)

  run!
end