|
22 | 22 | among others. See https://github.com/sk-/git-lint for the complete list. |
23 | 23 |
|
24 | 24 | Usage: |
25 | | - git-lint [-f | --force] [--json] [--last-commit] [FILENAME ...] |
26 | | - git-lint [-t | --tracked] [-f | --force] [--json] [--last-commit] |
27 | | - git-lint -h | --version |
| 25 | + git-lint [-f|--force] [--no-color] [--json] [--last-commit] [FILENAME ...] |
| 26 | + git-lint [-t|--tracked] [-f|--force] [--no-color] [--json] [--last-commit] |
| 27 | + git-lint -h|--version |
28 | 28 |
|
29 | 29 | Options: |
30 | 30 | -h Show the usage patterns. |
31 | 31 | --version Prints the version number. |
| 32 | + --no-color Disable colored output. |
32 | 33 | -f --force Shows all the lines with problems. |
33 | 34 | -t --tracked Lints only tracked files. |
34 | 35 | --json Prints the result as a json string. Useful to use it in |
|
57 | 58 | import gitlint.linters as linters |
58 | 59 | from gitlint.version import __VERSION__ |
59 | 60 |
|
60 | | -ERROR = termcolor.colored('ERROR', 'red', attrs=('bold', )) |
61 | | -SKIPPED = termcolor.colored('SKIPPED', 'yellow', attrs=('bold', )) |
62 | | -OK = termcolor.colored('OK', 'green', attrs=('bold', )) |
63 | | - |
64 | 61 |
|
65 | 62 | def find_invalid_filenames(filenames, repository_root): |
66 | 63 | """Find files that does not exist, are not in the repo or are directories. |
@@ -202,6 +199,16 @@ def main(argv, stdout=sys.stdout, stderr=sys.stderr): |
202 | 199 |
|
203 | 200 | vcs, repository_root = get_vcs_root() |
204 | 201 |
|
| 202 | + error = 'ERROR' |
| 203 | + skipped = 'SKIPPED' |
| 204 | + okay = 'OK' |
| 205 | + |
| 206 | + color = not arguments['--no-color'] and sys.stdout.isatty() |
| 207 | + if color: |
| 208 | + error = termcolor.colored(error, 'red', attrs=('bold', )) |
| 209 | + skipped = termcolor.colored(skipped, 'yellow', attrs=('bold', )) |
| 210 | + okay = termcolor.colored(okay, 'green', attrs=('bold', )) |
| 211 | + |
205 | 212 | if vcs is None: |
206 | 213 | stderr.write('fatal: Not a git repository' + linesep) |
207 | 214 | return 128 |
@@ -250,20 +257,22 @@ def main(argv, stdout=sys.stdout, stderr=sys.stderr): |
250 | 257 | rel_filename = os.path.relpath(filename) |
251 | 258 |
|
252 | 259 | if not json_output: |
253 | | - stdout.write('Linting file: %s%s' % (termcolor.colored( |
254 | | - rel_filename, attrs=('bold', )), linesep)) |
| 260 | + filename = rel_filename |
| 261 | + if color: |
| 262 | + filename = termcolor.colored(filename, attrs=('bold', )) |
| 263 | + stdout.write('Linting file: %s%s' % (filename, linesep)) |
255 | 264 |
|
256 | 265 | output_lines = [] |
257 | 266 | if result.get('error'): |
258 | | - output_lines.extend('%s: %s' % (ERROR, reason) |
| 267 | + output_lines.extend('%s: %s' % (error, reason) |
259 | 268 | for reason in result.get('error')) |
260 | 269 | linter_not_found = True |
261 | 270 | if result.get('skipped'): |
262 | | - output_lines.extend('%s: %s' % (SKIPPED, reason) |
| 271 | + output_lines.extend('%s: %s' % (skipped, reason) |
263 | 272 | for reason in result.get('skipped')) |
264 | 273 | if not result.get('comments', []): |
265 | 274 | if not output_lines: |
266 | | - output_lines.append(OK) |
| 275 | + output_lines.append(okay) |
267 | 276 | else: |
268 | 277 | files_with_problems += 1 |
269 | 278 | for data in result['comments']: |
|
0 commit comments