Hopefully successfully integrate proper repo.
This commit is contained in:
52
code/iottb-project/iottb/scripts/generate_help.py
Executable file
52
code/iottb-project/iottb/scripts/generate_help.py
Executable file
@@ -0,0 +1,52 @@
|
||||
import click
|
||||
from io import StringIO
|
||||
import sys
|
||||
|
||||
# Import your CLI app here
|
||||
from iottb.main import cli
|
||||
|
||||
"""Script to generate the help text and write to file.
|
||||
|
||||
Definitely needs better formatting.
|
||||
Script is also not very flexible.
|
||||
"""
|
||||
|
||||
|
||||
def get_help_text(command):
|
||||
"""Get the help text for a given command."""
|
||||
help_text = StringIO()
|
||||
with click.Context(command) as ctx:
|
||||
# chatgpt says this helps: was right
|
||||
sys_stdout = sys.stdout
|
||||
sys.stdout = help_text
|
||||
try:
|
||||
click.echo(command.get_help(ctx))
|
||||
finally:
|
||||
sys.stdout = sys_stdout
|
||||
return help_text.getvalue()
|
||||
|
||||
|
||||
def write_help_to_file(cli, filename):
|
||||
"""Write help messages of all commands and subcommands to a file."""
|
||||
with open(filename, 'w') as f:
|
||||
# main
|
||||
f.write(f"Main Command: iottb\n")
|
||||
f.write(get_help_text(cli))
|
||||
f.write("\n\n")
|
||||
|
||||
# go through subcommands
|
||||
for cmd_name, cmd in cli.commands.items():
|
||||
f.write(f"Command: {cmd_name}\n")
|
||||
f.write(get_help_text(cmd))
|
||||
f.write("\n\n")
|
||||
|
||||
# subcommands of subcommands
|
||||
if isinstance(cmd, click.Group):
|
||||
for sub_cmd_name, sub_cmd in cmd.commands.items():
|
||||
f.write(f"Subcommand: {cmd_name} {sub_cmd_name}\n")
|
||||
f.write(get_help_text(sub_cmd))
|
||||
f.write("\n\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
write_help_to_file(cli, "help_messages.md")
|
||||
4
code/iottb-project/iottb/scripts/sudo_iottb
Normal file
4
code/iottb-project/iottb/scripts/sudo_iottb
Normal file
@@ -0,0 +1,4 @@
|
||||
#/bin/sh
|
||||
echo 'Running iottb as sudo'
|
||||
sudo $(which python) iottb $@
|
||||
echo 'Finished executing iottb with sudo'
|
||||
Reference in New Issue
Block a user