5
5
"""
6
6
7
7
import os
8
+ import json
8
9
import argparse
9
10
10
11
from datetime import datetime
@@ -35,6 +36,11 @@ def start():
35
36
help = 'Introduction that will be added to the top of the document' ,
36
37
default = 'This document contains documentation of all configurations exported by the IntuneCD tool'
37
38
)
39
+ parser .add_argument (
40
+ '-j' , '--jsondata' ,
41
+ help = 'Lets you configure line 1-4 using a JSON string: "{\\ "title\\ ": \\ "demo\\ ", \\ "intro\\ ": \\ "demo\\ ", '
42
+ '\\ "tenant\\ ": \\ "demo\\ ", \\ "updated\\ ": \\ "demo\\ "}" '
43
+ )
38
44
parser .add_argument (
39
45
'-m' , '--maxlength' ,
40
46
help = 'Maximum length of the configuration value, values with a higher count will be displayed with "Value '
@@ -49,7 +55,7 @@ def start():
49
55
50
56
args = parser .parse_args ()
51
57
52
- def run_documentation (configpath , outpath , tenantname , maxlength , split ):
58
+ def run_documentation (configpath , outpath , tenantname , jsondata , maxlength , split ):
53
59
54
60
now = datetime .now ()
55
61
current_date = now .strftime ("%d/%m/%Y %H:%M:%S" )
@@ -136,16 +142,40 @@ def run_documentation(configpath, outpath, tenantname, maxlength, split):
136
142
# Document Settings Catalog
137
143
document_configs (f'{ configpath } /Settings Catalog' , outpath , 'Settings Catalog' , maxlength , split )
138
144
145
+ if jsondata :
146
+ json_dict = json .loads (jsondata )
147
+ if "title" in json_dict :
148
+ title = json_dict ["title" ]
149
+ else :
150
+ title = "MEM Documentation"
151
+ if "intro" in json_dict :
152
+ intro = json_dict ["intro" ]
153
+ else :
154
+ intro = args .intro
155
+ if "tenant" in json_dict :
156
+ tenant = json_dict ["tenant" ]
157
+ else :
158
+ tenant = f'**Tenant:** { tenantname } '
159
+ if "updated" in json_dict :
160
+ updated = json_dict ["updated" ]
161
+ else :
162
+ updated = f'**Document updated on:**'
163
+ else :
164
+ title = "MEM Documentation"
165
+ intro = args .intro
166
+ tenant = f'**Tenant:** { tenantname } '
167
+ updated = f'**Document updated on:**'
168
+
139
169
if split :
140
170
files = get_md_files ()
141
171
index_md = f'{ configpath } /index.md'
142
172
md_file (index_md )
143
173
144
174
with open (index_md , 'w' ) as doc :
145
- l1 = '# MEM Documentation \n \n '
146
- l2 = f'{ args . intro } \n \n '
147
- l3 = f'**Tenant:** { tenantname } \n \n '
148
- l4 = f'**Document updated on:** { current_date } \n \n '
175
+ l1 = f '# { title } \n \n '
176
+ l2 = f'{ intro } \n \n '
177
+ l3 = f'{ tenant } \n \n '
178
+ l4 = f'{ updated } { current_date } \n \n '
149
179
l5 = '## File index \n \n '
150
180
doc .writelines ([l1 , l2 , l3 , l4 , l5 ])
151
181
for file in files :
@@ -154,13 +184,13 @@ def run_documentation(configpath, outpath, tenantname, maxlength, split):
154
184
else :
155
185
document = markdown_toclify (input_file = outpath , back_to_top = True , exclude_h = [3 ])
156
186
with open (outpath , 'w' ) as doc :
157
- l1 = '# MEM Documentation \n \n '
158
- l2 = f'{ args . intro } \n \n '
159
- l3 = f'**Tenant:** { tenantname } \n \n '
160
- l4 = f'**Document updated on:** { current_date } \n \n '
187
+ l1 = f '# { title } \n \n '
188
+ l2 = f'{ intro } \n \n '
189
+ l3 = f'{ tenant } \n \n '
190
+ l4 = f'{ updated } { current_date } \n \n '
161
191
doc .writelines ([l1 , l2 , l3 , l4 , document ])
162
192
163
- run_documentation (args .path , args .outpath , args .tenantname , args .maxlength , args .split )
193
+ run_documentation (args .path , args .outpath , args .tenantname , args .jsondata , args . maxlength , args .split )
164
194
165
195
166
196
if __name__ == '__main__' :
0 commit comments