[diffoscope] 01/04: diffoscope: Specify choices for --list-tools switch.
Mattia Rizzolo
mattia at debian.org
Sat Jan 21 00:19:46 CET 2017
This is an automated email from the git hooks/post-receive script.
mattia pushed a commit to branch master
in repository diffoscope.
commit 3253f1452538469d6b6f4d3f5fc8189b9fbc6a57
Author: Brett Smith <brettcsmith at brettcsmith.org>
Date: Fri Dec 30 23:18:14 2016 -0500
diffoscope: Specify choices for --list-tools switch.
This gives the user more information about what they can specify as an
argument, and generates a nicer error message if they give an unrecognized
argument.
With that done, we can simplify the implementation of ListToolsAction,
because argparse has already validated the argument.
Signed-off-by: Mattia Rizzolo <mattia at debian.org>
---
diffoscope/main.py | 20 ++++++++------------
diffoscope/tools.py | 13 ++++++++-----
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/diffoscope/main.py b/diffoscope/main.py
index c374d8d..64e06fa 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -62,7 +62,11 @@ def create_parser():
parser.add_argument('--version', action='version',
version='diffoscope %s' % VERSION)
parser.add_argument('--list-tools', nargs='?', type=str, action=ListToolsAction,
- help='Show external tools required and exit')
+ metavar='DISTRO', choices=sorted(OS_NAMES),
+ help='Show external tools required and exit. '
+ 'DISTRO can be one of {%(choices)s}. '
+ 'If specified, the output will list packages in that '
+ 'distribution that satisfy these dependencies.')
parser.add_argument('--debug', dest='debug', action='store_true',
default=False, help='Display debug messages')
parser.add_argument('--debugger', action='store_true',
@@ -184,20 +188,12 @@ class ListToolsAction(argparse.Action):
print("External-Tools-Required: ", end='')
print(', '.join(sorted(tool_required.all)))
if os_override:
- if os_override in OS_NAMES.keys():
- os_list = [os_override]
- else:
- print()
- print("No package mapping found for: {} (possible values: {})".format(os_override, ", ".join(sorted(OS_NAMES.keys()))), file=sys.stderr)
- sys.exit(1)
+ os_list = [os_override]
else:
current_os = get_current_os()
- if current_os in OS_NAMES.keys():
- os_list = [current_os]
- else:
- os_list = OS_NAMES.keys()
+ os_list = [current_os] if (current_os in OS_NAMES) else iter(OS_NAMES)
for os in os_list:
- print("Available-in-{}-packages: ".format(OS_NAMES.get(os, os)), end='')
+ print("Available-in-{}-packages: ".format(OS_NAMES[os]), end='')
print(', '.join(sorted(filter(None, {
EXTERNAL_TOOLS.get(k, {}).get(os, None)
for k in tool_required.all
diff --git a/diffoscope/tools.py b/diffoscope/tools.py
index 8393284..8af5aa3 100644
--- a/diffoscope/tools.py
+++ b/diffoscope/tools.py
@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
+import collections
import platform
import functools
@@ -28,11 +29,13 @@ from .profiling import profile
# calls
find_executable = functools.lru_cache()(find_executable)
-OS_NAMES = {
- 'arch': 'Arch Linux',
- 'debian': 'Debian',
- 'FreeBSD': 'FreeBSD',
-}
+# The output of --help and --list-tools will use the order of this dict.
+# Please keep it alphabetized.
+OS_NAMES = collections.OrderedDict([
+ ('arch', 'Arch Linux'),
+ ('debian', 'Debian'),
+ ('FreeBSD', 'FreeBSD'),
+])
def tool_required(command):
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the diffoscope
mailing list