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".
|
2022-12-02 17:46:09 +00:00
|
|
|
# Python 3
|
2020-07-18 06:21:02 +00:00
|
|
|
|
|
|
|
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:
|
2021-11-22 13:49:24 +00:00
|
|
|
gap_pos = None
|
2023-12-18 14:43:58 +00:00
|
|
|
sub_cmd = line.split(',')[0].strip() # only take the first sub-command before the comma
|
|
|
|
if ' ' in sub_cmd:
|
2020-07-18 06:21:02 +00:00
|
|
|
gap_pos = sub_cmd.index(' ')
|
2021-11-22 13:49:24 +00:00
|
|
|
sub_cmd = cur_cmd + ' ' + sub_cmd[:gap_pos]
|
2020-07-18 06:21:02 +00:00
|
|
|
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-10-08 08:15:20 +00:00
|
|
|
# When --help is generated one needs to make sure none of the
|
|
|
|
# urfave-cli `EnvVars:` defaults get triggered
|
|
|
|
# Unset everything we can find via: grep -ho 'EnvVars:.*' -r * | sort -u
|
|
|
|
for e in [ "LOTUS_PATH", "LOTUS_MARKETS_PATH", "LOTUS_MINER_PATH", "LOTUS_STORAGE_PATH", "LOTUS_WORKER_PATH", "WORKER_PATH", "LOTUS_PANIC_REPORT_PATH", "WALLET_PATH" ]:
|
|
|
|
os.environ.pop(e, None)
|
|
|
|
|
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')
|
2023-12-18 14:43:58 +00:00
|
|
|
generate_lotus_cli('lotus-provider')
|