Skip to content

Commit

Permalink
feat. Can now list the available fixes with --listfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamere-allo-peter committed Mar 20, 2022
1 parent 19df8b0 commit 1d2b5ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ optional arguments:
-v, --version display this program's version number and exit.
-b, --backup make a backup copy of original files as `.orig`
-d, --debug output debug information to stderr.
-l, --listfixes output the list of available fixes.
-j, --jsonsummary output JSON summary to stderr.
-p, --plainsummary output plain text summary to stderr.
-s, --summary output colored plain text summary to stderr.
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.8
version = 0.3.9
name = yamlfixer-opt-nc
description = automates the fixing of problems reported by yamllint
long_description = file: README.md
Expand Down
22 changes: 21 additions & 1 deletion 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.8"
__version__ = "0.3.9"
__author__ = "OPT-NC"
__license__ = "GPLv3+"
__copyright__ = "Copyright (C) 2021-%s %s" % (time.strftime("%Y",
Expand Down Expand Up @@ -441,6 +441,21 @@ def statistics(self):
}
self.info(json.dumps(summarymapping, indent=4))

def listfixes(self):
"""List all the available fixes."""
availablefixes = []
notfilefixer = FileFixer(self, "-")
notpbfixer = ProblemFixer(notfilefixer, 0, 0, "")
for methodname in [m for m in dir(notpbfixer) if m.startswith('fix_')]:
docstring = getattr(notpbfixer, methodname).__doc__
for prob in [pb.strip()[2:] for pb in docstring.splitlines()[1:]]:
if prob:
availablefixes.append(prob)
self.info("fixes:")
for f in sorted(availablefixes):
self.info(f" - {f}")
return EXIT_OK

def fix(self):
"""Fix all files."""
for filename in self.arguments.filenames:
Expand Down Expand Up @@ -504,6 +519,9 @@ def run():
cmdline.add_argument("-d", "--debug",
action="store_true",
help="output debug information to stderr.")
cmdline.add_argument("-l", "--listfixes",
action="store_true",
help="output the list of available fixes.")
mutuallyexclusive = cmdline.add_mutually_exclusive_group()
mutuallyexclusive.add_argument("-j", "--jsonsummary",
action="store_true",
Expand All @@ -521,4 +539,6 @@ def run():
default=["-"], # Read from stdin if no file is specified
help="the YAML files to fix. Use `-` to read from `stdin`.")
arguments = cmdline.parse_args()
if arguments.listfixes:
return YAMLFixer(arguments).listfixes()
return YAMLFixer(arguments).fix()

0 comments on commit 1d2b5ef

Please sign in to comment.