Skip to content

Commit 0db59a6

Browse files
authored
Merge pull request #8 from Flamefire/master
Add --style support
2 parents 2425bbf + d20d1fd commit 0db59a6

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ Available version are from 5 to 9.\
3737
Default: 9\
3838
Example: 9
3939

40+
### `style`
41+
42+
Style to use.\
43+
Results in the appropriate --style parameter.\
44+
Default: file\
45+
Example: chromium
46+
4047
## Example usage
4148

4249
```yml
@@ -53,7 +60,8 @@ jobs:
5360
- uses: DoozyX/clang-format-lint-action@v0.5
5461
with:
5562
source: '.'
56-
exclude: './third_party'
63+
exclude: './third_party ./external'
5764
extensions: 'h,cpp'
5865
clangFormatVersion: 9
66+
style: chromium
5967
```

action.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ inputs:
2121
description: 'Version of clang-format'
2222
required: false
2323
default: '9'
24+
style:
25+
description: 'Formatting style to use'
26+
required: false
27+
default: 'file'
2428
runs:
2529
using: 'docker'
26-
image: 'docker://doozy/clang-format-lint:0.5'
30+
image: 'Dockerfile'
2731
args:
32+
- --clang-format-executable /clang-format/clang-format${{ inputs.clangFormatVersion }}
33+
- -r
34+
- --style ${{ inputs.style }}
35+
- --extensions ${{ inputs.extensions }}
36+
- --exclude ${{ inputs.exclude }}
2837
- ${{ inputs.source }}
29-
- ${{ inputs.exclude }}
30-
- ${{ inputs.extensions }}
31-
- ${{ inputs.clangFormatVersion }}

entrypoint.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
cd "$GITHUB_WORKSPACE"
44

5-
ln -s /clang-format/clang-format${INPUT_CLANGFORMATVERSION} /usr/bin/clang-format
6-
/run-clang-format.py -r --exclude ${INPUT_EXCLUDE} --extensions ${INPUT_EXTENSIONS} ${INPUT_SOURCE}
5+
/run-clang-format.py $*

run-clang-format.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def run_clang_format_diff(args, file):
131131
except IOError as exc:
132132
raise DiffError(str(exc))
133133
invocation = [args.clang_format_executable, file]
134+
if args.style:
135+
invocation.append('-style=' + args.style)
134136

135137
# Use of utf-8 to decode the process output.
136138
#
@@ -278,6 +280,10 @@ def main():
278280
default=[],
279281
help='exclude paths matching the given glob-like pattern(s)'
280282
' from recursive search')
283+
parser.add_argument(
284+
'--style',
285+
help='Formatting style to use (default: file)',
286+
default='file')
281287

282288
args = parser.parse_args()
283289

@@ -329,7 +335,11 @@ def main():
329335
extensions=args.extensions.split(','))
330336

331337
if not files:
332-
return
338+
print_trouble(parser.prog, 'No files found', use_colors=colored_stderr)
339+
return ExitStatus.TROUBLE
340+
341+
if not args.quiet:
342+
print('Processing %s files: %s' % (len(files), ', '.join(files)))
333343

334344
njobs = args.j
335345
if njobs == 0:

0 commit comments

Comments
 (0)