Cope with the fact that some of our commands output --help to stdout, some to stderr.
[dcpomatic.git] / doc / manual / cli.py
1 #!/usr/bin/python3
2 import subprocess
3 import os
4 import sys
5
6 print('<para>')
7 print('<itemizedlist>')
8
9 os.chdir('../..')
10 for l in subprocess.run(['run/%s' % sys.argv[1], '--help'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.splitlines():
11     l = l.strip().decode('UTF-8')
12     if not l.startswith('-'):
13         continue
14
15     s = l.split()
16     print('<listitem>', end='')
17
18     e = 0
19     n = 0
20     if l.startswith('-') and not l.startswith('--'):
21         print('<code>%s</code>, ' % s[0][:-1], end='')
22         n = 1
23         e = len(s[0]) + 2
24
25     if l.find('<') != -1:
26         print('<code>%s %s</code>' % (s[n], s[n+1].replace('<', '&lt;').replace('>', '&gt;')), end='')
27         e += len(s[n]) + len(s[n+1]) + 1
28     else:
29         print('<code>%s</code>' % s[n], end='')
30         e += len(s[n])
31
32     desc = l[e:].strip()
33     fixed_desc = ''
34     t = False
35     for i in desc:
36         if i == '"' and t == False:
37             fixed_desc += '&#8220;'
38             t = True
39         elif i == '"' and t == True:
40             fixed_desc += '&#8221;'
41             t = False
42         else:
43             fixed_desc += i
44
45     print(' &#8212; %s</listitem>' % fixed_desc)
46
47 print('</itemizedlist>')
48 print('</para>', end='')
49 os.chdir('doc/manual')