Coverage for src/cli/entrypoint.py: 100.00%

35 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-07 23:52 +0000

1#!/usr/bin/env python3 

2 

3# Standard libraries 

4from argparse import Namespace 

5from enum import Enum 

6from importlib.resources import as_file as resource_as_file, files as resources_files 

7from pathlib import Path 

8from subprocess import CalledProcessError, check_output, DEVNULL 

9from time import sleep 

10 

11# Components 

12from ..package.bundle import Bundle 

13from ..prints.colors import Colors 

14from ..system.platform import Platform 

15 

16# Entrypoint class, pylint: disable=too-few-public-methods 

17class Entrypoint: 

18 

19 # Enumerations 

20 Result = Enum('Result', [ 

21 'SUCCESS', 

22 'FINALIZE', 

23 'ERROR', 

24 'CRITICAL', 

25 ]) 

26 

27 # Assets 

28 ASSET_GIT_CONFIGURATION_ALIAS: str = 'alias.gitconfig' 

29 

30 # CLI 

31 @staticmethod 

32 def cli(options: Namespace) -> Result: 

33 

34 # Variable 

35 asset_path: Path 

36 

37 # Enable or disable profiles configurations 

38 if options.enable or options.disable: 

39 

40 # Acquire asset configuration 

41 try: 

42 with resource_as_file( 

43 resources_files(Bundle.RESOURCES_ASSETS) \ 

44 .joinpath(Entrypoint.ASSET_GIT_CONFIGURATION_ALIAS) 

45 ) as file_path: 

46 asset_path = file_path # pragma: no cover 

47 except ModuleNotFoundError: 

48 asset_path = Path(__file__).resolve().parent.parent.joinpath( 

49 'assets').joinpath(Entrypoint.ASSET_GIT_CONFIGURATION_ALIAS) 

50 

51 # Disable asset configuration 

52 if options.disable: 

53 print(' ') 

54 print(f'{Colors.BOLD} - Disable Git alias configurations: ' 

55 f'{Colors.GREEN}{asset_path}' 

56 f'{Colors.RESET}') 

57 Platform.flush() 

58 

59 # Reset asset configuration 

60 if options.enable or options.disable: 

61 try: 

62 check_output( 

63 [ 

64 'git', 

65 'config', 

66 '--global', 

67 '--unset', 

68 'include.path', 

69 str(asset_path), 

70 ], 

71 stderr=DEVNULL, 

72 ) 

73 except CalledProcessError: 

74 pass 

75 

76 # Enable asset configuration 

77 if options.enable: 

78 print(' ') 

79 print(f'{Colors.BOLD} - Enable Git alias configurations: ' 

80 f'{Colors.GREEN}{asset_path}' 

81 f'{Colors.RESET}') 

82 Platform.flush() 

83 check_output([ 

84 'git', 

85 'config', 

86 '--global', 

87 '--add', 

88 'include.path', 

89 str(asset_path), 

90 ]) 

91 

92 # Delay execution 

93 sleep(1) 

94 

95 # Result 

96 return Entrypoint.Result.SUCCESS