Skip to content

Commit

Permalink
feat. More portable color scheme. Make colored summary the default, w…
Browse files Browse the repository at this point in the history
…hile keeping the option for a plain text one.
  • Loading branch information
tamere-allo-peter committed Mar 17, 2022
1 parent 1c6c885 commit 5f2e209
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This software automatically fixes some errors and warnings reported by
`yamllint`.

```shell
usage: yamlfixer [-h] [-v] [-b] [-d] [-j | -c | -s] [file [file ...]]
usage: yamlfixer [-h] [-v] [-b] [-d] [-j | -p | -s] [file [file ...]]

Fix formatting problems in YAML documents. If no file is specified,
then reads input from `stdin`.
Expand All @@ -60,9 +60,10 @@ optional arguments:
-b, --backup make a backup copy of original files as `.orig`
-d, --debug output debug information to stderr.
-j, --jsonsummary output JSON summary to stderr.
-c, --colorsummary output colored plain text summary to stderr. If stderr
is not a TTY output is identical to --summary.
-s, --summary output plain text summary to stderr.
-p, --plainsummary output plain text summary to stderr.
-s, --summary output colored plain text summary to stderr.
If stderr is not a TTY output is identical to
--plainsummary.
```
yamlfixer launches `yamllint` on each specified filename, then parses
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
version = 0.3.4
version = 0.3.5
name = yamlfixer-opt-nc
description = automates the fixing of problems reported by yamllint
long_description = file: README.md
Expand Down
24 changes: 12 additions & 12 deletions yamlfixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import argparse
import json

__version__ = "0.3.4"
__version__ = "0.3.5"
__author__ = "OPT-NC"
__license__ = "GPLv3+"
__copyright__ = "Copyright (C) 2021-%s %s" % (time.strftime("%Y",
Expand Down Expand Up @@ -46,11 +46,11 @@
EXIT_NOK = -1
EXIT_PROBLEM = -2

COLORSEQ = {"PASSED": "32m",
"MODIFIED": "34m",
"SKIPPED": "36m",
"ERROR": "31m",
"UNKNOWN": "33m",
COLORSEQ = {"PASSED": "38;2;0;255;0m",
"MODIFIED": "38;2;0;0;255m",
"SKIPPED": "38;2;255;0;255m",
"ERROR": "38;2;255;0;0m",
"UNKNOWN": "38;2;255;255;0m",
}

class ProblemFixer:
Expand Down Expand Up @@ -410,7 +410,7 @@ def error(self, message): # pylint: disable=no-self-use

def statistics(self):
"""Output some statistics."""
if self.arguments.summary or self.arguments.colorsummary:
if self.arguments.summary or self.arguments.plainsummary:
self.info(f"Files to fix: {len(self.arguments.filenames)}")
self.info(f"{self.passed} files successfully passed yamllint strict mode")
self.info(f"{self.modified} files were modified")
Expand All @@ -422,7 +422,7 @@ def statistics(self):
msg = f" (handled {handled}/{issues})"
else:
msg = ""
if self.arguments.colorsummary and sys.stderr.isatty():
if self.arguments.summary and sys.stderr.isatty():
status = f"\033[{COLORSEQ.get(status.strip(), '0m')}{status}\033[0m"
self.info(f"{status} {filename}{msg}")
elif self.arguments.jsonsummary:
Expand Down Expand Up @@ -508,13 +508,13 @@ def run():
mutuallyexclusive.add_argument("-j", "--jsonsummary",
action="store_true",
help="output JSON summary to stderr.")
mutuallyexclusive.add_argument("-c", "--colorsummary",
mutuallyexclusive.add_argument("-p", "--plainsummary",
action="store_true",
help="output colored plain text summary to stderr. "
"If stderr is not a TTY output is identical to --summary.")
help="output plain text summary to stderr.")
mutuallyexclusive.add_argument("-s", "--summary",
action="store_true",
help="output plain text summary to stderr.")
help="output colored plain text summary to stderr. "
"If stderr is not a TTY output is identical to --plainsummary.")
cmdline.add_argument("filenames",
nargs="*",
metavar="file",
Expand Down

0 comments on commit 5f2e209

Please sign in to comment.