Coverage for gengive/cli.py: 100.00%

27 statements  

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

1#! /usr/bin/env python3 

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

3# pylint: disable=line-too-long 

4"""Commandline API gateway for turvallisuusneuvonta.""" 

5import sys 

6from typing import List, Union 

7 

8import typer 

9 

10import gengive 

11import gengive.gengive as gg 

12 

13APP_NAME = 'Render text (Danish: gengive tekst).' 

14APP_ALIAS = 'gengive' 

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 gengive version and exit', 

29 is_eager=True, 

30 ) 

31) -> None: 

32 """ 

33 Render text (Danish: gengive tekst). 

34 """ 

35 if version: 

36 typer.echo(f'{APP_NAME} version {gengive.__version__}') 

37 raise typer.Exit() 

38 

39 

40@app.command('render') 

41def render( 

42 source: str = typer.Argument(''), 

43 manuscript: str = typer.Option( 

44 '', 

45 '-m', 

46 '--manuscript', 

47 help='Path to or name of input manuscript folder (no default)', 

48 metavar='<manuscript>', 

49 ), 

50 target: str = typer.Option( 

51 'default', 

52 '-t', 

53 '--target', 

54 help='Target facet to render manuscript as (default is default)', 

55 metavar='target', 

56 ), 

57 publisher_root: str = typer.Option( 

58 str(gg.PUBLISHER_ROOT), 

59 '-p', 

60 '--publisher-root', 

61 help=f'Publisher root (default is {gg.PUBLISHER_ROOT})', 

62 metavar='target', 

63 ), 

64 render_root: str = typer.Option( 

65 str(gg.PUBLISHER_ROOT), 

66 '-r', 

67 '--render-root', 

68 help=f'Render root (default is {gg.RENDER_ROOT})', 

69 metavar='target', 

70 ), 

71 verify: bool = typer.Option( 

72 False, 

73 '-n', 

74 '--dry-run', 

75 help='Dry run (default is False)', 

76 ), 

77) -> int: 

78 """ 

79 render the manuscript for target. 

80 """ 

81 command = 'render' if not verify else 'verify' 

82 manuscript = manuscript if manuscript else source 

83 target = target if target else gg.DEFAULT_TARGET 

84 action = [command, publisher_root, manuscript, target, render_root] 

85 return sys.exit(gg.main(action)) 

86 

87 

88@app.command('version') 

89def app_version() -> None: 

90 """ 

91 Display the gengive version and exit 

92 """ 

93 callback(True) 

94 

95 

96# pylint: disable=expression-not-assigned 

97# @app.command() 

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

99 """Delegate processing to functional module.""" 

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

101 return gg.main(argv)