1+ from  json  import  load 
2+ from  datetime  import  date 
3+ 
4+ 
5+ ###### Parameters ###### 
6+ 
7+ # path to the help.json file 
8+ pathToHelpFile  =  "../src/data/help.json" 
9+ # man page section 
10+ manSection  =  1   
11+ # version (left footer) 
12+ versionNumber  =  "Fastfetch 1.0"  
13+ # title (center header) 
14+ titlePage  =  "Fastfetch man page"  
15+ # date (center footer) 
16+ todayDate  =  date .today ().strftime ("%b %d %Y" ) # format : "Month (abreviation) Day Year" 
17+ 
18+ 
19+ # text displayed in the "NAME" section 
20+ nameSection  =  "fastfetch - a neofetch-like tool for fetching system \  
21+  information and displaying them in a pretty way"     
22+ 
23+ # text displayed in the "DESCRIPTION" section 
24+ descriptionSection  =  "A maintained, feature-rich and performance \  
25+  oriented, neofetch like system information tool."    
26+ 
27+ # text displayed in the "BUGS" section 
28+ bugSection  =  "Please report bugs to : https://github.com/fastfetch-cli/fastfetch/issues" 
29+ 
30+ 
31+ ###### Text Decorations Tags ###### 
32+ 
33+ startUnderline  =  "\\ fI"  # start underline text tag 
34+ endUnderline  =  "\\ fR"  # end underline text tag 
35+ 
36+ startBold  =  "\\ fB"  # start bold text tag 
37+ endBold  =  "\\ fR"  # end bold text tag 
38+ 
39+ startItalic  =  "\\ fI"  # start italic text tag 
40+ endItalic  =  "\\ fP"  # end italic text tag 
41+ 
42+ 
43+ ###### Argument decoration ###### 
44+ 
45+ ### optional arguments tags ### 
46+ 
47+ # if an optional argument is displayed as [?optArg] (with "optArg" underlined), this value should be f"[?{startUnderline}" 
48+ startOptionalArgument  =  f"[{ startItalic }  ?" 
49+ # if an optional argument is displayed as [?optArg] (with "optArg underlined"), this value should be f"{endUnderline}]" 
50+ endOptionalArgument  =  f"{ endItalic }  ]"  
51+ 
52+ # mandatory arguments tags 
53+ startMandatoryArgument  =  ""  
54+ endMandatoryArgument  =  "" 
55+ 
56+ def  generateManPage ():
57+ 
58+     # importing the JSON file 
59+     try :
60+         with  open (pathToHelpFile , 'r' ) as  jsonFile :
61+             helpFileData  =  load (jsonFile ) # json.load 
62+     except  IOError  as  error :
63+         print ("Error with file" , pathToHelpFile , ":" , error )
64+         return 
65+     
66+ 
67+     ######## Start printing the generated .1 file ######## 
68+ 
69+ 
70+     ###### header, footer & config ##### 
71+ 
72+     print (f".TH man { manSection }  " , end = " " )
73+     print (f"\" { todayDate } \" " , end = " " )
74+     print (f"\" { versionNumber } \" " , end = " " )
75+     print (f"\" { titlePage } \" " )
76+ 
77+ 
78+     ###### Name ###### 
79+ 
80+     print (".SH NAME" )
81+     print (nameSection )
82+ 
83+ 
84+     ##### Synopsis ###### 
85+ 
86+     print (".SH SYNOPSIS" )
87+     print (".B fastfetch" )
88+     print (f"[{ startUnderline }  OPTIONS{ endUnderline }  ]" )
89+ 
90+ 
91+     ##### Description ##### 
92+ 
93+     print (".SH DESCRIPTION" )
94+     print (descriptionSection )
95+ 
96+ 
97+     ###### Options ###### 
98+ 
99+     print (".SH OPTIONS" )
100+ 
101+     # loop through every options sections 
102+     for  key , value  in  helpFileData .items ():
103+ 
104+         # print new subsection 
105+         print (f".SS { key }  :" )
106+ 
107+         # loop through every option in a section 
108+         for  option  in  value :
109+             # list of existing keys for this option 
110+             keyList  =  option .keys ()
111+ 
112+             # start a new "option" entry 
113+             print (".TP" )
114+             print (startBold , end = "" )
115+ 
116+             # short option (-opt) 
117+             if  "short"  in  keyList :
118+                 print (f"\-{  option ['short' ] }  " , end = "" )
119+                 # if also have a long option, print a comma 
120+                 if  "long"  in  keyList :
121+                     print (", " , end = "" )
122+ 
123+             # long option (--option) 
124+             if  "long"  in  keyList :
125+                 print (f"\-\-{  option ['long' ] }  " , end = "" )
126+ 
127+             print (endBold , end = " " )
128+             
129+             
130+ 
131+ 
132+ 
133+ 
134+ 
135+ 
136+ if  __name__  ==  "__main__" :
137+     generateManPage ()
0 commit comments