Class: Pilot::CommandsGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



18
19
20
# File 'pilot/lib/pilot/commands_generator.rb', line 18

def self.start
  new.run
end

Instance Method Details

#convert_options(options) ⇒ Object



22
23
24
25
26
# File 'pilot/lib/pilot/commands_generator.rb', line 22

def convert_options(options)
  o = options.__hash__.dup
  o.delete(:verbose)
  o
end

#create_config(options) ⇒ Object



170
171
172
173
# File 'pilot/lib/pilot/commands_generator.rb', line 170

def create_config(options)
  config = FastlaneCore::Configuration.create(Pilot::Options.available_options, convert_options(options))
  return config
end

#handle_multiple(action, args, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'pilot/lib/pilot/commands_generator.rb', line 28

def handle_multiple(action, args, options)
  mgr = Pilot::TesterManager.new
  config = create_config(options)
  args.push(config[:email]) if config[:email] && args.empty?
  args.push(UI.input("Email address of the tester: ")) if args.empty?
  failures = []
  args.each do |address|
    config[:email] = address
    begin
      mgr.public_send(action, config)
    rescue => ex
      # no need to show the email address in the message if only one specified
      message = (args.count > 1) ? "[#{address}]: #{ex}" : ex
      failures << message
      UI.error(message)
    end
  end
  UI.user_error!("Some operations failed: #{failures.join(', ')}") unless failures.empty?
end

#runObject



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
# File 'pilot/lib/pilot/commands_generator.rb', line 48

def run
  program :name, 'pilot'
  program :version, Fastlane::VERSION
  program :description, Pilot::DESCRIPTION
  program :help, "Author", "Felix Krause <pilot@krausefx.com>"
  program :help, "Website", "https://fastlane.tools"
  program :help, "Documentation", "https://docs.fastlane.tools/actions/pilot/"
  program :help_formatter, FastlaneCore::HelpFormatter

  global_option("--verbose") { FastlaneCore::Globals.verbose = true }

  command :upload do |c|
    c.syntax = "fastlane pilot upload"
    c.description = "Uploads a new binary to Apple TestFlight"

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

    c.action do |args, options|
      config = create_config(options)
      Pilot::BuildManager.new.upload(config)
    end
  end

  command :distribute do |c|
    c.syntax = "fastlane pilot distribute"
    c.description = "Distribute a previously uploaded binary to Apple TestFlight"

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

    c.action do |args, options|
      config = create_config(options)
      Pilot::BuildManager.new.distribute(config)
    end
  end

  command :builds do |c|
    c.syntax = "fastlane pilot builds"
    c.description = "Lists all builds for given application"

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

    c.action do |args, options|
      config = create_config(options)
      Pilot::BuildManager.new.list(config)
    end
  end

  command :add do |c|
    c.syntax = "fastlane pilot add"
    c.description = "Adds new external tester(s) to a specific app (if given). This will also add an existing tester to an app."

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

    c.action do |args, options|
      handle_multiple('add_tester', args, options)
    end
  end

  command :list do |c|
    c.syntax = "fastlane pilot list"
    c.description = "Lists all registered testers, both internal and external"

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

    c.action do |args, options|
      config = create_config(options)
      UI.user_error!("You must include an `app_identifier` to list testers") unless config[:app_identifier]
      Pilot::TesterManager.new.list_testers(config)
    end
  end

  command :find do |c|
    c.syntax = "fastlane pilot find"
    c.description = "Find tester(s) (internal or external) by their email address"

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

    c.action do |args, options|
      handle_multiple('find_tester', args, options)
    end
  end

  command :remove do |c|
    c.syntax = "fastlane pilot remove"
    c.description = "Remove external tester(s) by their email address"

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

    c.action do |args, options|
      handle_multiple('remove_tester', args, options)
    end
  end

  command :export do |c|
    c.syntax = "fastlane pilot export"
    c.description = "Exports all external testers to a CSV file"

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

    c.action do |args, options|
      config = create_config(options)
      Pilot::TesterExporter.new.export_testers(config)
    end
  end

  command :import do |c|
    c.syntax = "fastlane pilot import"
    c.description = "Import external testers from a CSV file called testers.csv"

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

    c.action do |args, options|
      config = create_config(options)
      Pilot::TesterImporter.new.import_testers(config)
    end
  end

  default_command(:help)

  run!
end