2020-07-18 06:21:02 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Generate lotus command lines documents as text and markdown in folder "lotus/documentation/en".
|
|
|
|
# Python 2.7
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
2021-04-29 17:44:39 +00:00
|
|
|
def generate_lotus_cli(prog):
|
|
|
|
output_folder = 'documentation/en'
|
|
|
|
md_file = open('%s/cli-%s.md' % (output_folder, prog), 'w') # set the name of md output
|
2020-07-18 06:21:02 +00:00
|
|
|
|
|
|
|
def get_cmd_recursively(cur_cmd):
|
2021-04-29 17:44:39 +00:00
|
|
|
depth = cur_cmd.count(' ')
|
|
|
|
md_file.writelines(('\n' * min(depth, 1)) + ('#' * depth) + '# ' + cur_cmd[2:] + '\n')
|
2020-07-18 06:21:02 +00:00
|
|
|
|
|
|
|
cmd_flag = False
|
|
|
|
|
2021-04-29 17:44:39 +00:00
|
|
|
print('> ' + cur_cmd)
|
|
|
|
cmd_help_output = os.popen(cur_cmd + ' -h')
|
2020-07-18 06:21:02 +00:00
|
|
|
cmd_help_output_lines = cmd_help_output.readlines()
|
|
|
|
|
|
|
|
md_file.writelines('```\n')
|
|
|
|
md_file.writelines(cmd_help_output_lines)
|
|
|
|
md_file.writelines('```\n')
|
|
|
|
|
|
|
|
for line in cmd_help_output_lines:
|
|
|
|
try:
|
|
|
|
line = line.strip()
|
|
|
|
if line == 'COMMANDS:':
|
|
|
|
cmd_flag = True
|
|
|
|
if cmd_flag is True and line == '':
|
|
|
|
cmd_flag = False
|
|
|
|
if cmd_flag is True and line[-1] != ':' and 'help, h' not in line:
|
|
|
|
gap_pos = 0
|
|
|
|
sub_cmd = line
|
|
|
|
if ' ' in line:
|
|
|
|
gap_pos = sub_cmd.index(' ')
|
|
|
|
if gap_pos:
|
|
|
|
sub_cmd = cur_cmd + ' ' + sub_cmd[:gap_pos]
|
|
|
|
get_cmd_recursively(sub_cmd)
|
|
|
|
except Exception as e:
|
|
|
|
print('Fail to deal with "%s" with error:\n%s' % (line, e))
|
|
|
|
|
2021-04-29 17:44:39 +00:00
|
|
|
get_cmd_recursively('./' + prog)
|
2020-07-18 06:21:02 +00:00
|
|
|
md_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-04-29 18:01:23 +00:00
|
|
|
os.putenv("LOTUS_VERSION_IGNORE_COMMIT", "1")
|
2021-04-29 17:44:39 +00:00
|
|
|
generate_lotus_cli('lotus')
|
|
|
|
generate_lotus_cli('lotus-miner')
|
|
|
|
generate_lotus_cli('lotus-worker')
|