Class: Fastlane::Actions::ClangFormatAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



82
83
84
# File 'lib/fastlane/plugin/clang_format/actions/clang_format_action.rb', line 82

def self.authors
  ["Marcin Stepnowski"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/clang_format/actions/clang_format_action.rb', line 39

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :clang_format_path,
                                env_name: 'FL_CLANG_FORMAT_PATH',
                                description: 'Path to clang-format if you want use it from specific path',
                                optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :inplace,
                                env_name: 'FL_CLANG_FORMAT_INPLACE',
                                description: 'Inplace edit :files, if specified',
                                optional: true,
                                default_value: false,
                                type: Boolean),
    FastlaneCore::ConfigItem.new(key: :style,
                                env_name: 'FL_CLANG_FORMAT_STYLE',
                                description: [
                                  'Coding style, currently supports:',
                                  'LLVM, Google, Chromium, Mozilla, WebKit.',
                                  'Use style:file to load style configuration from',
                                  '.clang-format file located in one of the parent',
                                  'directories of the source file (or current',
                                  'directory for stdin).',
                                  'Use style:"{key: value, ...}" to set specific',
                                  'parameters, e.g.:',
                                  'style:"{BasedOnStyle: llvm, IndentWidth: 8}"'
                                ].join(' '),
                                optional: true,
                                default_value: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :verbose,
                                env_name: 'FL_CLANG_FORMAT_VERBOSE',
                                description: 'If true, shows the list of processed files',
                                optional: true,
                                default_value: false,
                                type: Boolean),
    FastlaneCore::ConfigItem.new(key: :files,
                                env_name: 'FL_CLANG_FORMAT_FILES',
                                description: 'Array of files to check formatting',
                                optional: false,
                                type: Array)
  ]
end

.descriptionObject



25
26
27
# File 'lib/fastlane/plugin/clang_format/actions/clang_format_action.rb', line 25

def self.description
  "A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C"
end

.detailsObject



29
30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/clang_format/actions/clang_format_action.rb', line 29

def self.details
  [
    'If no arguments are specified, it formats the code from standard input',
    'and writes the result to the standard output.',
    'If :files are given, it reformats the files. If :inplace is specified',
    'together with :files, the files are edited in-place. Otherwise, the',
    'result is written to the standard output'
  ].join(' ')
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/fastlane/plugin/clang_format/actions/clang_format_action.rb', line 86

def self.is_supported?(platform)
  true
end

.run(params) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fastlane/plugin/clang_format/actions/clang_format_action.rb', line 6

def self.run(params)
  clang_format_path = params[:clang_format_path]
  clang_format_path ||= 'clang-format'

  cmd = []
  cmd << clang_format_path
  inplace = params[:inplace]
  cmd << "-i" if inplace
  style = params[:style]
  cmd << "--style=#{style}" if style
  cmd << "--verbose" if params[:verbose]
  files = params[:files]
  Array(files).each do |file|
    cmd << file
  end
  Actions.sh(cmd.join(' '))
  UI.success('Everything is formatted correctly now! 💪')
end