@cryptotaxi247 / kubo / commits / 380068e6f

cmdrefgen to generate command ref

Juan Batiz-Benet committed Feb 16, 2015 at 13:53 UTC 380068e6ff161ef50c40b963f065aa40d5cbb8d0
1 file changed +38
bin/gencmdref new
+38
@@ -0,0 +1,38 @@
1 +#!/usr/bin/env python
2 +
3 +import os
4 +import sys
5 +import datetime
6 +import subprocess
7 +
8 +from subprocess import check_output
9 +
10 +def run(cmd):
11 + return check_output(cmd)
12 +
13 +def main():
14 + lines = [l.strip() for l in sys.stdin]
15 +
16 + print '# ipfs command reference'
17 + print ''
18 + print 'generated on', datetime.datetime.now()
19 + print ''
20 + for line in lines:
21 + print '- [%s](#%s)' % (line, line.replace(' ', '-'))
22 + print ''
23 +
24 + for line in lines:
25 + print '## %s' % line
26 + print ''
27 + print '```'
28 + print run((line + ' --help').split(' ')).strip()
29 + print '```'
30 + print ''
31 +
32 +if __name__ == '__main__':
33 + if '-h' in sys.argv or '--help' in sys.argv:
34 + print 'usage: ipfs commands | %s >cmdref.md' % sys.argv[0]
35 + print 'outputs all commands with --help to a markdown file'
36 + exit(0)
37 +
38 + main()