Coverage for taulukko/cli.py: 100.00%
21 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-05 19:15:40 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-05 19:15:40 +00:00
1"""Commandline API gateway for taulukko."""
3import sys
5import typer
7import taulukko
8import taulukko.taulukko as tau
10APP_NAME = 'Table (Finnish Taulukko) glued together to transform into hands-free living.'
11APP_ALIAS = 'taulukko'
12app = typer.Typer(
13 add_completion=False,
14 context_settings={'help_option_names': ['-h', '--help']},
15 no_args_is_help=True,
16)
19@app.callback(invoke_without_command=True)
20def callback(
21 version: bool = typer.Option(
22 False,
23 '-V',
24 '--version',
25 help='Display the taulukko version and exit',
26 is_eager=True,
27 )
28) -> None:
29 """
30 Table (Finnish Taulukko) glued together to transform into hands-free living.
32 Given an html file or URL the tool produces a markdown file of the tables
33 below `taulukko-md`.
34 """
35 if version:
36 typer.echo(f'{APP_NAME} version {taulukko.__version__}')
37 raise typer.Exit()
40@app.command('extract')
41def extract(
42 source: str = typer.Argument(tau.STDIN),
43 inp: str = typer.Option(
44 '',
45 '-i',
46 '--input',
47 help='Path to input file (default is reading from standard in)',
48 metavar='<sourcepath>',
49 ),
50) -> int:
51 """
52 Translate from zip file containing a tree of html and media files to a folder with markdown.
53 """
54 command = 'extract'
55 incoming = inp if inp else (source if source != tau.STDIN else '')
56 action = [command, str(incoming)]
57 return sys.exit(tau.main(action))
60@app.command('version')
61def app_version() -> None:
62 """
63 Display the taulukko version and exit
64 """
65 callback(True)