From 601b0feaf3065b030153fa06f116c18c77210ee2 Mon Sep 17 00:00:00 2001 From: Martin Di Paola Date: Mon, 13 Jun 2022 20:08:57 -0300 Subject: [PATCH] Fix -x-turn-echo-off adding the missing bool argument --- Makefile | 4 ++-- byexample/cmdline.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 401b3372..06980025 100644 --- a/Makefile +++ b/Makefile @@ -90,8 +90,8 @@ modules-test: clean_test docs-test: clean_test @$(python_bin) -W error test/r.py @test/minimum.env -- *.md - @$(python_bin) -W error test/r.py @test/minimum.env -x-turn-echo-off --skip docs/advanced/echo-filtering.md docs/recipes/python-doctest.md -- `find docs \( -name languages -prune -o -name "*.md" \) -type f` - @$(python_bin) -W error test/r.py @test/minimum.env docs/advanced/echo-filtering.md + @$(python_bin) -W error test/r.py @test/minimum.env -x-turn-echo-off yes --skip docs/advanced/echo-filtering.md docs/recipes/python-doctest.md -- `find docs \( -name languages -prune -o -name "*.md" \) -type f` + @$(python_bin) -W error test/r.py @test/minimum.env -x-turn-echo-off no docs/advanced/echo-filtering.md @$(python_bin) -W error test/r.py @test/minimum.env -o '+py-doctest' docs/recipes/python-doctest.md @$(python_bin) -m doctest docs/recipes/python-doctest.md @make -s clean_test diff --git a/byexample/cmdline.py b/byexample/cmdline.py index 09151657..362b6be7 100644 --- a/byexample/cmdline.py +++ b/byexample/cmdline.py @@ -89,6 +89,18 @@ def _show_failures_type(item): return failures_num +def _true_false_type(answer): + answer = str(answer).lower() + if answer in {'yes', 'true', '1', 'y'}: + return True + elif answer in {'no', 'false', '0', 'n'}: + return False + else: + raise argparse.ArgumentTypeError( + "Invalid answer '%s'. Expected 'yes' or 'no'." % answer + ) + + class HelpExtraFormatter(argparse.HelpFormatter): __hide = True EPILOG = "==EPILOG==" @@ -522,8 +534,9 @@ def parse_args(args=None): ) g.add_argument( "-x-turn-echo-off", - action='store_true', + action='store', default=False, + type=_true_false_type, help= "turn off the echo on each example execution (ignored if force-echo-filtering is on); (default: %(default)s)." )