Class: Fastlane::ActionsList

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/documentation/actions_list.rb

Class Method Summary collapse

Class Method Details

.action_subclass_error(name) ⇒ Object



102
103
104
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 102

def self.action_subclass_error(name)
  "Please update your action '#{name}' to be a subclass of `Action` by adding ` < Action` after your class name."
end

.all_actions(platform = nil) ⇒ Object

Iterates through all available actions and yields from there



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 170

def self.all_actions(platform = nil)
  action_symbols = Fastlane::Actions.constants.select { |c| Fastlane::Actions.const_get(c).kind_of?(Class) && c != :TestSampleCodeAction }
  action_symbols.sort.each do |symbol|
    action = Fastlane::Actions.const_get(symbol)

    # We allow classes that don't respond to is_supported? to come through because we want to list
    # them as broken actions in the table, regardless of platform specification
    next if platform && action.respond_to?(:is_supported?) && !action.is_supported?(platform.to_sym)

    name = symbol.to_s.gsub(/Action$/, '').fastlane_underscore
    yield(action, name)
  end
end

.find_action_named(name) ⇒ Object



184
185
186
187
188
189
190
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 184

def self.find_action_named(name)
  all_actions do |action, action_name|
    return action if action_name == name
  end

  nil
end

.parse_options(options, fill_all = true) ⇒ Object

Helper:



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 193

def self.parse_options(options, fill_all = true)
  rows = []
  rows << [options] if options.kind_of?(String)

  if options.kind_of?(Array)
    options.each do |current|
      if current.kind_of?(FastlaneCore::ConfigItem)
        rows << [current.key.to_s.yellow, current.deprecated ? current.description.red : current.description, current.env_name, current.help_default_value]
      elsif current.kind_of?(Array)
        # Legacy actions that don't use the new config manager
        UI.user_error!("Invalid number of elements in this row: #{current}. Must be 2 or 3") unless [2, 3].include?(current.count)
        rows << current
        rows.last[0] = rows.last.first.yellow # color it yellow :)
        rows.last << nil while fill_all && rows.last.count < 4 # to have a nice border in the table
      end
    end
  end

  rows
end


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
39
40
41
42
43
44
45
46
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 12

def self.print_all(platform: nil)
  rows = []
  all_actions(platform) do |action, name|
    current = []

    if Fastlane::Actions.is_deprecated?(action)
      current << "#{name} (DEPRECATED)".deprecated
    else
      current << name.yellow
    end

    if action < Action
      current << action.description.to_s.remove_markdown if action.description

      authors = Array(action.author || action.authors)
      current << authors.first.green if authors.count == 1
      current << "Multiple".green if authors.count > 1
    else
      UI.error(action_subclass_error(name))
      current << "Please update action file".red
      current << ' '
    end
    rows << current
  end

  puts(Terminal::Table.new(
         title: "Available fastlane actions".green,
         headings: ['Action', 'Description', 'Author'],
         rows: FastlaneCore::PrintTable.transform_output(rows)
  ))
  puts("  Platform filter: #{platform}".magenta) if platform
  puts("  Total of #{rows.count} actions")

  puts("\nGet more information for one specific action using `fastlane action [name]`\n".green)
end


132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 132

def self.print_options(action, name)
  options = parse_options(action.available_options) if action.available_options

  if options
    puts(Terminal::Table.new(
           title: "#{name} Options".green,
           headings: ['Key', 'Description', 'Env Var', 'Default'],
           rows: FastlaneCore::PrintTable.transform_output(options)
    ))
  else
    puts("No available options".yellow)
  end
  puts("* = default value is dependent on the user's system")
  puts("")
end


148
149
150
151
152
153
154
155
156
157
158
159
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 148

def self.print_output_variables(action, name)
  output = action.output
  return if output.nil? || output.empty?

  puts(Terminal::Table.new(
         title: "#{name} Output Variables".green,
         headings: ['Key', 'Description'],
         rows: FastlaneCore::PrintTable.transform_output(output.map { |key, desc| [key.yellow, desc] })
  ))
  puts("Access the output values using `lane_context[SharedValues::VARIABLE_NAME]`")
  puts("")
end


161
162
163
164
165
166
167
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 161

def self.print_return_value(action, name)
  return unless action.return_value

  puts(Terminal::Table.new(title: "#{name} Return Value".green,
                            rows: FastlaneCore::PrintTable.transform_output([[action.return_value]])))
  puts("")
end


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 82

def self.print_suggestions(filter)
  if !filter.nil? && filter.length > 1
    action_names = []
    all_actions(nil) do |action_ref, action_name|
      action_names << action_name
    end

    corrections = []

    if defined?(DidYouMean::SpellChecker)
      spell_checker = DidYouMean::SpellChecker.new(dictionary: action_names)
      corrections << spell_checker.correct(filter).compact
    end

    corrections << action_names.select { |name| name.include?(filter) }

    puts("Did you mean: #{corrections.flatten.uniq.join(', ')}?".green) unless corrections.flatten.empty?
  end
end


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
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 106

def self.print_summary(action, name)
  rows = []

  if action.description
    description = action.description.to_s.remove_markdown
    rows << [description]
    rows << [' ']
  end

  if action.details
    details = action.details.to_s.remove_markdown
    details.split("\n").each do |detail|
      row = detail.empty? ? ' ' : detail
      rows << [row]
    end

    rows << [' ']
  end

  authors = Array(action.author || action.authors)
  rows << ["Created by #{authors.join(', ').green}"] unless authors.empty?

  puts(Terminal::Table.new(title: name.green, rows: FastlaneCore::PrintTable.transform_output(rows)))
  puts("")
end

.run(filter: nil, platform: nil) ⇒ Object



3
4
5
6
7
8
9
10
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 3

def self.run(filter: nil, platform: nil)
  require 'terminal-table'
  if filter
    show_details(filter: filter)
  else
    print_all(platform: platform)
  end
end

.show_details(filter: nil) ⇒ Object



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
# File 'fastlane/lib/fastlane/documentation/actions_list.rb', line 48

def self.show_details(filter: nil)
  puts("Loading documentation for #{filter}:".green)
  puts("")

  action = find_action_named(filter)

  if action
    unless action < Action
      UI.user_error!(action_subclass_error(filter))
    end

    print_summary(action, filter)
    print_options(action, filter)
    print_output_variables(action, filter)
    print_return_value(action, filter)

    if Fastlane::Actions.is_deprecated?(action)
      puts("==========================================".deprecated)
      puts("This action (#{filter}) is deprecated".deprecated)
      puts(action.deprecated_notes.to_s.remove_markdown.deprecated) if action.deprecated_notes
      puts("==========================================\n".deprecated)
    end

    puts("More information can be found on https://docs.fastlane.tools/actions/#{filter}")
    puts("")
  else
    puts("Couldn't find action for the given filter.".red)
    puts("==========================================\n".red)

    print_all # show all available actions instead
    print_suggestions(filter)
  end
end