Skip to content

Commit 0e26c0e

Browse files
committed
Added ability to configure line 1-4 with a json string
1 parent bf76e25 commit 0e26c0e

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

src/IntuneCD/run_documentation.py

+40-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import os
8+
import json
89
import argparse
910

1011
from datetime import datetime
@@ -35,6 +36,11 @@ def start():
3536
help='Introduction that will be added to the top of the document',
3637
default='This document contains documentation of all configurations exported by the IntuneCD tool'
3738
)
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+
)
3844
parser.add_argument(
3945
'-m', '--maxlength',
4046
help='Maximum length of the configuration value, values with a higher count will be displayed with "Value '
@@ -49,7 +55,7 @@ def start():
4955

5056
args = parser.parse_args()
5157

52-
def run_documentation(configpath, outpath, tenantname, maxlength, split):
58+
def run_documentation(configpath, outpath, tenantname, jsondata, maxlength, split):
5359

5460
now = datetime.now()
5561
current_date = now.strftime("%d/%m/%Y %H:%M:%S")
@@ -136,16 +142,40 @@ def run_documentation(configpath, outpath, tenantname, maxlength, split):
136142
# Document Settings Catalog
137143
document_configs(f'{configpath}/Settings Catalog', outpath, 'Settings Catalog', maxlength, split)
138144

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+
139169
if split:
140170
files = get_md_files()
141171
index_md = f'{configpath}/index.md'
142172
md_file(index_md)
143173

144174
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'
149179
l5 = '## File index \n\n'
150180
doc.writelines([l1, l2, l3, l4, l5])
151181
for file in files:
@@ -154,13 +184,13 @@ def run_documentation(configpath, outpath, tenantname, maxlength, split):
154184
else:
155185
document = markdown_toclify(input_file=outpath, back_to_top=True, exclude_h=[3])
156186
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'
161191
doc.writelines([l1, l2, l3, l4, document])
162192

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)
164194

165195

166196
if __name__ == '__main__':

0 commit comments

Comments
 (0)