11import os , sys
22from pathlib import Path
33from types import SimpleNamespace as sn
4+ from typing import Dict , List , Optional
45if sys .platform == 'win32' : import colorama ; colorama .init () # enable ANSI color support
56
67from . import data as datalib , pkg , settings
2526 gry = '\x1b [90m' # gray
2627)
2728
28- def data (msg , * args , ** kwargs ) : print (f'\n { colors .bw } { msg .format (* args , ** kwargs )} { colors .nc } ' )
29- def dim (msg , * args , ** kwargs ) : print (f'\n { colors .gry } { msg .format (* args , ** kwargs )} { colors .nc } ' )
30- def docs_url (cli ) : tip (f'{ cli .msgs .tip_FOR_MORE_HELP_VISIT } :\n { cli .urls .docs } ' )
31- def error (msg , * args , ** kwargs ) : print (f'\n { colors .br } ERROR: { msg .format (* args , ** kwargs )} { colors .nc } ' )
32- def help_cmd (cli ) : info (f"{ cli .msgs .log_TYPE } '{ cli .cmds [0 ]} --help' { cli .msgs .log_FOR_AVAIL_OPTIONS } \n " )
33- def info (msg , * args , end = '' , ** kwargs ) : print (f'\n { colors .by } { msg .format (* args , ** kwargs )} { colors .nc } ' , end = end )
34- def init_cmd (cli ) : info (f"{ cli .msgs .log_TYPE } '{ cli .cmds [0 ]} --init' { cli .msgs .log_TO_CREATE_DEFAULT_CONFIG } \n " )
35- def overwrite_print (msg , * args , ** kwargs ):
29+ def data (msg : str , * args , ** kwargs ) -> None : print (f'\n { colors .bw } { msg .format (* args , ** kwargs )} { colors .nc } ' )
30+ def dim (msg : str , * args , ** kwargs ) -> None : print (f'\n { colors .gry } { msg .format (* args , ** kwargs )} { colors .nc } ' )
31+ def docs_url (cli : sn ) -> None : tip (f'{ cli .msgs .tip_FOR_MORE_HELP_VISIT } :\n { cli .urls .docs } ' )
32+ def error (msg : str , * args , ** kwargs ) -> None : print (f'\n { colors .br } ERROR: { msg .format (* args , ** kwargs )} { colors .nc } ' )
33+ def help_cmd (cli : sn ) -> None : info (f"{ cli .msgs .log_TYPE } '{ cli .cmds [0 ]} --help' { cli .msgs .log_FOR_AVAIL_OPTIONS } \n " )
34+ def info (msg : str , * args , end : str = '' , ** kwargs ) -> None :
35+ print (f'\n { colors .by } { msg .format (* args , ** kwargs )} { colors .nc } ' , end = end )
36+ def init_cmd (cli : sn ) -> None :
37+ info (f"{ cli .msgs .log_TYPE } '{ cli .cmds [0 ]} --init' { cli .msgs .log_TO_CREATE_DEFAULT_CONFIG } \n " )
38+ def overwrite_print (msg : str , * args , ** kwargs ) -> None :
3639 sys .stdout .write ('\r ' + msg .format (* args , ** kwargs ).ljust (terminal_width )[:terminal_width ])
37- def success (msg , * args , ** kwargs ) : print (f'\n { colors .bg } { msg .format (* args , ** kwargs )} { colors .nc } ' )
38- def tip (msg , * args , ** kwargs ) : print (f'\n { colors .bc } TIP: { msg .format (* args , ** kwargs )} { colors .nc } ' )
39- def version (cli ) :
40+ def success (msg : str , * args , ** kwargs ) -> None : print (f'\n { colors .bg } { msg .format (* args , ** kwargs )} { colors .nc } ' )
41+ def tip (msg : str , * args , ** kwargs ) -> None : print (f'\n { colors .bc } TIP: { msg .format (* args , ** kwargs )} { colors .nc } ' )
42+ def version (cli : sn ) -> None :
4043 print (f'\n { colors .by } { cli .name } \n { colors .bw } { cli .msgs .log_VERSION .lower ()} : { cli .version } { colors .nc } ' )
41- def warn (msg , * args , ** kwargs ) : print (f'\n { colors .bo } WARNING: { msg .format (* args , ** kwargs )} { colors .nc } ' )
44+ def warn (msg : str , * args , ** kwargs ) -> None : print (f'\n { colors .bo } WARNING: { msg .format (* args , ** kwargs )} { colors .nc } ' )
4245
43- def warn_legacy_option (cli , flag : str , source : str ) -> None :
46+ def warn_legacy_option (cli : sn , flag : str , source : str ) -> None :
4447 warned_set = _warned_keys [source ]
4548 if flag in warned_set : return
4649 canonical_key = settings .get_canonical_key (flag )
@@ -62,13 +65,13 @@ def warn_legacy_option(cli, flag: str, source: str) -> None:
6265 msg += f' { cli .msgs .warn_AND_WILL_BE_REMOVED } @ v{ next_maj_ver } '
6366 warn (msg ) ; warned_set .add (flag )
6467
65- def cmd_docs_url_exit (cli , msg = '' , cmd = 'help' ):
68+ def cmd_docs_url_exit (cli : sn , msg : str = '' , cmd : str = 'help' ) -> None :
6669 if msg : error (msg )
6770 help_cmd (cli ) if cmd == 'help' else init_cmd (cli )
6871 docs_url (cli )
6972 sys .exit (1 )
7073
71- def debug (msg , cli = None , * args , ** kwargs ):
74+ def debug (msg : str , cli : Optional [ sn ] = None , * args , ** kwargs ) -> None :
7275 if '--debug' not in sys .argv [1 :]: return
7376
7477 # Init --debug [target]
@@ -89,7 +92,7 @@ def debug(msg, cli=None, *args, **kwargs):
8992
9093 print (f'\n { colors .by } DEBUG: { msg } { colors .nc } ' )
9194
92- def final_summary (msgs , summary_dict ) :
95+ def final_summary (msgs : sn , summary_dict : Dict [ str , List [ str ]]) -> None :
9396 success (f'{ msgs .log_ALL_JSON_PROCESSED } !' )
9497 for name , file_set in summary_dict .items ():
9598 if file_set :
@@ -98,7 +101,7 @@ def final_summary(msgs, summary_dict):
98101 data (f'{ msgs .log_KEYS } { status } : { len (file_set )} ' )
99102 print (f'{ status_color } [\n ' + '\n ' .join (file_set ) + f'\n ]{ colors .nc } ' )
100103
101- def trunc (msg , end = '\n ' ):
104+ def trunc (msg : str , end : str = '\n ' ) -> None :
102105 truncated_lines = [
103106 line if len (line ) < terminal_width else line [:terminal_width - 4 ] + '...' for line in msg .splitlines ()]
104107 print ('\n ' .join (truncated_lines ), end = end )
0 commit comments