Coverage for prosessilouhinta/cli.py: 79.55%

32 statements  

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

1"""Commandline API gateway for prosessilouhnita.""" 

2 

3import sys 

4 

5import typer 

6 

7import prosessilouhinta 

8import prosessilouhinta.prosessilouhinta as pm 

9 

10APP_NAME = 'Process mining (Finnish prosessilouhinta) from eventlogs.' 

11APP_ALIAS = 'prosessilouhnita' 

12app = typer.Typer( 

13 add_completion=False, 

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

15 no_args_is_help=True, 

16) 

17 

18 

19@app.callback(invoke_without_command=True) 

20def callback( 

21 version: bool = typer.Option( 

22 False, 

23 '-V', 

24 '--version', 

25 help='Display the prosessilouhinta version and exit', 

26 is_eager=True, 

27 ) 

28) -> None: 

29 """ 

30 Process mining (Finnish prosessilouhinta) from eventlogs. 

31 """ 

32 if version: 

33 typer.echo(f'{APP_NAME} version {prosessilouhinta.__version__}') 

34 raise typer.Exit() 

35 

36 

37@app.command('extract') 

38def extract( 

39 source: str = typer.Argument(pm.STDIN), 

40 target: str = typer.Argument(pm.STDOUT), 

41 inp: str = typer.Option( 

42 '', 

43 '-i', 

44 '--input', 

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

46 metavar='<sourcepath>', 

47 ), 

48 out: str = typer.Option( 

49 '', 

50 '-o', 

51 '--output', 

52 help='Path to non-existing output report file (default is writing to standard out)', 

53 metavar='<targetpath>', 

54 ), 

55 dry: bool = typer.Option( 

56 False, 

57 '-n', 

58 '--dryrun', 

59 help='Flag to execute without writing the extraction but a summary instead (default is False)', 

60 metavar='bool', 

61 ), 

62) -> int: 

63 """ 

64 Translate from a language to a 'langauge'. 

65 """ 

66 command = 'extract' 

67 incoming = inp if inp else (source if source != pm.STDIN else '') 

68 outgoing = out if out else (target if target != pm.STDOUT else '') 

69 dryrun = 'DRYRUN' if dry else '' 

70 action = [command, incoming, outgoing, dryrun] 

71 return sys.exit(pm.main(action)) 

72 

73 

74@app.command('cpa') 

75def cpa_dia( 

76 source: str = typer.Argument(pm.STDIN), 

77 inp: str = typer.Option( 

78 '', 

79 '-i', 

80 '--input', 

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

82 metavar='<sourcepath>', 

83 ), 

84) -> int: 

85 """ 

86 Apply Critical Path Analysis (CPA) on input and produce activity-on-nodes diagram for critical path. 

87 """ 

88 command = 'cpa' 

89 incoming = inp if inp else (source if source != pm.STDIN else '') 

90 if not incoming: 

91 print('No file path given to load the activities and dependencies from') 

92 return sys.exit(2) 

93 

94 action = [command, incoming] 

95 return sys.exit(pm.cpa_dia(action)) 

96 

97 

98@app.command('version') 

99def app_version() -> None: 

100 """ 

101 Display the prosessilouhinta version and exit 

102 """ 

103 callback(True)