23
23
}
24
24
25
25
framework_root = pathlib .Path (__file__ ).parent .parent .parent
26
+ default_metadata_path = (framework_root / 'db' / 'modules_metadata_base.json' )
26
27
27
28
def get_notes (module_metadata ):
28
29
tree = Tree ('Notes' , hide_root = True )
@@ -64,10 +65,11 @@ def get_bulleted_list(items):
64
65
def main ():
65
66
parser = argparse .ArgumentParser (description = 'fzuse helper' , conflict_handler = 'resolve' )
66
67
parser .add_argument ('module_name' , help = 'module name to display' )
68
+ parser .add_argument ('--metadata-path' , default = default_metadata_path , type = pathlib .Path , help = 'the path to the module metadata' )
67
69
parser .add_argument ('-v' , '--version' , action = 'version' , version = '%(prog)s Version: ' + __version__ )
68
70
arguments = parser .parse_args ()
69
71
70
- with ( framework_root / 'db' / 'modules_metadata_base.json' ) .open ('r' ) as file_h :
72
+ with arguments . metadata_path .open ('r' ) as file_h :
71
73
all_metadata = json .load (file_h )
72
74
module_metadata = next ((metadata for metadata in all_metadata .values () if metadata ['fullname' ] == arguments .module_name ), None )
73
75
if not module_metadata :
@@ -84,7 +86,7 @@ def main():
84
86
table .add_row ('[bold]Rank[/bold]' , RANKS [module_metadata ['rank' ]])
85
87
table .add_row ('[bold]Disclosed[/bold]' , module_metadata ['disclosure_date' ])
86
88
87
- console = Console ()
89
+ console = Console (color_system = '256' )
88
90
console .print (table )
89
91
90
92
panel_title = lambda v : f"[bold]{ v } [/bold]"
@@ -96,8 +98,13 @@ def main():
96
98
if module_metadata .get ('references' ):
97
99
console .print (Panel (get_references (module_metadata ), title = panel_title ('References' ), title_align = 'left' ))
98
100
if module_metadata .get ('path' , '' ):
99
- syntax = Syntax .from_path (framework_root / module_metadata ['path' ][1 :], background_color = 'default' , line_numbers = True )
100
- console .print (Panel (syntax , title = panel_title ('Source code' ), title_align = 'left' ))
101
+ if pathlib .Path (module_metadata ['path' ]).is_file ():
102
+ module_path = pathlib .Path (module_metadata ['path' ])
103
+ elif pathlib .Path (framework_root / module_metadata ['path' ][1 :]).is_file ():
104
+ module_path = pathlib .Path (framework_root / module_metadata ['path' ][1 :])
105
+ if module_path :
106
+ syntax = Syntax .from_path (module_path , background_color = 'default' , line_numbers = True )
107
+ console .print (Panel (syntax , title = panel_title ('Source code' ), title_align = 'left' ))
101
108
102
109
if __name__ == '__main__' :
103
110
main ()
0 commit comments