lotus/scripts/generate-lotus-cli.py
Andrew Jackson (Ajax) fd7f1a95e2
feat: curio: web based config edit (#11822)
* cfg edit 1

* jsonschema deps

* feat: lp mig - first few steps

* lp mig: default tasks

* code comments

* docs

* lp-mig-progress

* shared

* comments and todos

* fix: curio: rename lotus-provider to curio (#11645)

* rename provider to curio

* install gotext

* fix lint errors, mod tidy

* fix typo

* fix API_INFO and add gotext to circleCI

* add back gotext

* add gotext after remerge

* lp: channels doc

* finish easy-migration TODOs

* out generate

* merging and more renames

* avoid make-all

* minor doc stuff

* cu: make gen

* make gen fix

* make gen

* tryfix

* go mod tidy

* minor ez migration fixes

* ez setup - ui cleanups

* better error message

* guided setup colors

* better path to saveconfigtolayer

* loadconfigwithupgrades fix

* readMiner oops

* guided - homedir

* err if miner is running

* prompt error should exit

* process already running, miner_id sectors in migration

* dont prompt for language a second time

* check miner stopped

* unlock repo

* render and sql oops

* curio easyMig - some fixes

* easyMigration runs successfully

* lint

* part 2 of last

* message

* merge addtl

* fixing guided setup for myself

* warn-on-no-post

* EditorLoads

* cleanups and styles

* create info

* fix tests

* make gen

* change layout, add help button

* Duration custom json

* mjs naming

---------

Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com>
Co-authored-by: LexLuthr <lexluthr@protocol.ai>
Co-authored-by: LexLuthr <lexluthr@curiostorage.org>
2024-04-16 09:30:27 -05:00

63 lines
2.3 KiB
Python

#!/usr/bin/env python
# Generate lotus command lines documents as text and markdown in folder "lotus/documentation/en".
# Python 3
import os
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
def get_cmd_recursively(cur_cmd):
depth = cur_cmd.count(' ')
md_file.writelines(('\n' * min(depth, 1)) + ('#' * depth) + '# ' + cur_cmd[2:] + '\n')
cmd_flag = False
print('> ' + cur_cmd)
cmd_help_output = os.popen(cur_cmd + ' -h')
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 = None
sub_cmd = line.split(',')[0].strip() # only take the first sub-command before the comma
if ' ' in sub_cmd:
gap_pos = sub_cmd.index(' ')
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))
get_cmd_recursively('./' + prog)
md_file.close()
if __name__ == "__main__":
# 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)
# Set env var telling the binaries that we're generating docs
os.putenv("LOTUS_DOCS_GENERATION", "1")
os.putenv("LOTUS_VERSION_IGNORE_COMMIT", "1")
generate_lotus_cli('lotus')
generate_lotus_cli('lotus-miner')
generate_lotus_cli('lotus-worker')
generate_lotus_cli('curio')
generate_lotus_cli('sptool')