From 138a78357a0ebbeb59bb5a8a21e73d3cbbe24f21 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Mon, 20 Jun 2022 12:40:11 +0200 Subject: [PATCH] added --verbose option this one increases the loglevel to 'debug' --- CHANGELOG.md | 1 + blag/blag.py | 13 ++++++++++++- tests/test_blag.py | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17ef628..5d67ed7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [unreleased] - XXXX-XX-XX * Added --version option +* added --verbose option, that increases the loglevel to 'debug' * Improved quickstart: * respective default answers will be written to config if user provided no answer diff --git a/blag/blag.py b/blag/blag.py index 3c0a908..e84bc2b 100644 --- a/blag/blag.py +++ b/blag/blag.py @@ -39,6 +39,10 @@ def main(args=None): """ args = parse_args(args) + # set loglevel + if args.verbose: + logger.setLevel(logging.DEBUG) + logger.debug(f"This is blag {__VERSION__}.") args.func(args) @@ -61,6 +65,11 @@ def parse_args(args=None): action='version', version='%(prog)s '+__VERSION__, ) + parser.add_argument( + '-v', '--verbose', + action='store_true', + help='Verbose output.', + ) commands = parser.add_subparsers(dest='command') commands.required = True @@ -219,6 +228,7 @@ def build(args): os.makedirs(f'{args.output_dir}/{path}', exist_ok=True) # copy static files over + logger.info('Copying static files.') if os.path.exists(args.static_dir): shutil.copytree(args.static_dir, args.output_dir, dirs_exist_ok=True) @@ -281,7 +291,8 @@ def process_markdown(convertibles, input_dir, output_dir, articles = [] pages = [] for src, dst in convertibles: - logger.info(f'Processing {src}') + logger.debug(f'Processing {src}') + with open(f'{input_dir}/{src}', 'r') as fh: body = fh.read() diff --git a/tests/test_blag.py b/tests/test_blag.py index 2e032b9..72dbf37 100644 --- a/tests/test_blag.py +++ b/tests/test_blag.py @@ -287,3 +287,11 @@ def test_cli_version(capsys): # proper version reported out, _ = capsys.readouterr() assert blag.__VERSION__ in out + + +def test_cli_verbose(cleandir, caplog): + blag.main(['build']) + assert 'DEBUG' not in caplog.text + + blag.main(['--verbose', 'build']) + assert 'DEBUG' in caplog.text