Coverage for kohtaaminen/cli.py: 97.06%

26 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-04 19:02:00 +00:00

1#! /usr/bin/env python 

2# -*- coding: utf-8 -*- 

3# pylint: disable=line-too-long 

4"""Commandline API gateway for kohtaaminen.""" 

5import sys 

6from typing import List, Union 

7 

8import typer 

9 

10import kohtaaminen 

11import kohtaaminen.kohtaaminen as ko 

12 

13APP_NAME = 'Meeting, rendezvous, confluence (Finnish kohtaaminen) mark up, down, and up again' 

14APP_ALIAS = 'kohtaaminen' 

15app = typer.Typer( 

16 add_completion=False, 

17 context_settings={'help_option_names': ['-h', '--help']}, 

18 no_args_is_help=True, 

19) 

20 

21 

22@app.callback(invoke_without_command=True) 

23def callback( 

24 version: bool = typer.Option( 

25 False, 

26 '-V', 

27 '--version', 

28 help='Display the kohtaaminen version and exit', 

29 is_eager=True, 

30 ) 

31) -> None: 

32 """ 

33 Meeting, rendezvous, confluence (Finnish kohtaaminen) mark up, down, and up again. 

34 

35 Given a zip file containing a tree of html and media files following certain conventions, 

36 the tool produces a markdown media tree below `kohtaaminen-md`. 

37 """ 

38 if version: 38 ↛ exitline 38 didn't return from function 'callback', because the condition on line 38 was never false

39 typer.echo(f'{APP_NAME} version {kohtaaminen.__version__}') 

40 raise typer.Exit() 

41 

42 

43@app.command('translate') 

44def translate( 

45 source: str = typer.Argument(ko.STDIN), 

46 inp: str = typer.Option( 

47 '', 

48 '-i', 

49 '--input', 

50 help='Path to input file (default is reading from standard in)', 

51 metavar='<sourcepath>', 

52 ), 

53) -> int: 

54 """ 

55 Translate from zip file containing a tree of html and media files to a folder with markdown. 

56 """ 

57 command = 'translate' 

58 incoming = inp if inp else (source if source != ko.STDIN else '') 

59 action = [command, str(incoming)] 

60 return sys.exit(ko.main(action)) 

61 

62 

63@app.command('version') 

64def app_version() -> None: 

65 """ 

66 Display the kohtaaminen version and exit 

67 """ 

68 callback(True) 

69 

70 

71# pylint: disable=expression-not-assigned 

72# @app.command() 

73def main(argv: Union[List[str], None] = None) -> int: 

74 """Delegate processing to functional module.""" 

75 argv = sys.argv[1:] if argv is None else argv 

76 return ko.main(argv)