[diffoscope] 05/05: Show the list of supported file types in the manual and --help output. We can copy-paste this into the website, at least. Thanks to Jonathan Dowland for the suggestion. (Closes: #893443)

Chris Lamb chris at chris-lamb.co.uk
Sun Mar 18 22:00:11 CET 2018


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 1375ec5bc1f653c4588ac503f45a8c2fcb87ab58
Author: Chris Lamb <lamby at debian.org>
Date:   Sun Mar 18 14:45:00 2018 -0400

    Show the list of supported file types in the manual and --help output. We can copy-paste this into the website, at least. Thanks to Jonathan Dowland for the suggestion. (Closes: #893443)
---
 diffoscope/comparators/__init__.py |  7 +++++++
 diffoscope/main.py                 | 11 ++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 6cedc21..2e4e98f 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -126,3 +126,10 @@ class ComparatorManager(object):
                 ))
 
         logger.debug("Loaded %d comparator classes", len(self.classes))
+
+    def get_descriptions(self):
+        for x in self.classes:
+            try:
+                yield x.DESCRIPTION
+            except AttributeError:
+                pass
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 5a0f9e9..1e0b720 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -73,7 +73,7 @@ class BooleanAction(argparse.Action):
 def create_parser():
     parser = argparse.ArgumentParser(
         description='Calculate differences between two files or directories',
-        add_help=False)
+        add_help=False, formatter_class=HelpFormatter)
     parser.add_argument('path1', nargs='?', help='First file or directory to '
                         'compare. If omitted, tries to read a diffoscope diff from stdin.')
     parser.add_argument('path2', nargs='?', help='Second file or directory to '
@@ -265,6 +265,15 @@ def create_parser():
     return parser, post_parse
 
 
+class HelpFormatter(argparse.HelpFormatter):
+    def format_help(self, *args, **kwargs):
+        val = super().format_help(*args, **kwargs)
+        val = '{}\n\nfile formats supported:\n'.format(val)
+        for x in sorted(ComparatorManager().get_descriptions(), key=str.title):
+            val = '{}{}- {}{}.\n\n'.format(val, ' ' * 24, x[0].upper(), x[1:])
+        return val
+
+
 class RangeCompleter(object):
     def __init__(self, start, end=0, divisions=16):
         if end < start:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list