Coverage for mapology/cli.py: 76.19%

39 statements  

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

1# -*- coding: utf-8 -*- 

2# pylint: disable=line-too-long 

3"""Generate geojson data based leaflet driven web app from flat data files.""" 

4import sys 

5from typing import List, Union 

6 

7import mapology.countries_razor as razor 

8import mapology.icao as icao 

9import mapology.indexer as indexer 

10import mapology.prefixes as prefixer 

11import mapology.template_loader as template 

12 

13USAGE = """\ 

14Synopsis: 

15========= 

16- render airports per ICAO: 

17 mapology icao path/to/airborne/r/[IC/[ICAO/]] 

18- render prefix pages ICAO prefix: 

19 mapology prefix 

20- render index page collecting prefixes: 

21 mapology index 

22- render airport, prefix, and index page tree completely: 

23 mapology tree 

24- shave off some properties from the natural earth country data set: 

25 mapology shave 

26- eject the templates into the folder given (default EJECTED) and create the folder if it does not exist: 

27 mapology eject [into] 

28- this usage info: 

29 mapology [-h,--help] 

30""" 

31 

32 

33# pylint: disable=expression-not-assigned 

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

35 """Delegate processing to functional module.""" 

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

37 usage = any(p in ('-h', '--help') for p in argv) or not argv 

38 command, call, vector = '', None, [] 

39 if not usage and argv: 

40 command = argv[0] 

41 vector = argv[1:] 

42 if command == 'icao': 

43 call = icao.main 

44 elif command == 'prefix': 

45 call = prefixer.main 

46 elif command == 'index': 

47 call = indexer.main 

48 elif command == 'tree': 48 ↛ 49line 48 didn't jump to line 49, because the condition on line 48 was never true

49 call = ((icao.main, vector), (prefixer.main, []), (indexer.main, [])) # type: ignore 

50 elif command == 'shave': 

51 call = razor.main 

52 elif command == 'eject': 52 ↛ 53line 52 didn't jump to line 53, because the condition on line 52 was never true

53 call = template.eject 

54 

55 if usage or not call: 

56 print(USAGE) 

57 return 0 if usage else 2 

58 

59 if not isinstance(call, tuple): 59 ↛ 62line 59 didn't jump to line 62, because the condition on line 59 was never false

60 return call(vector) 

61 

62 code = 0 

63 for cmd, vec in call: 

64 code = cmd(vec) 

65 if code: 

66 return code 

67 

68 return code