Use real script name
This commit is contained in:
parent
fa8680646f
commit
6434301ac0
|
@ -18,7 +18,7 @@ def find_git_root(path) -> str:
|
|||
|
||||
|
||||
def iter_commands(
|
||||
module_name: str,
|
||||
tool_name: str,
|
||||
cmd_chain: list,
|
||||
cliobj: click.Group | click.Command,
|
||||
depth: int = 1,
|
||||
|
@ -31,11 +31,11 @@ def iter_commands(
|
|||
|
||||
for name in sorted(cliobj.commands):
|
||||
yield from iter_commands(
|
||||
module_name, cmd_chain + [name], cliobj.commands[name], depth=depth + 1
|
||||
tool_name, cmd_chain + [name], cliobj.commands[name], depth=depth + 1
|
||||
)
|
||||
else:
|
||||
ctx = click.get_current_context()
|
||||
cmd = f"{module_name} {' '.join(cmd_chain)}"
|
||||
cmd = f"{tool_name} {' '.join(cmd_chain)}"
|
||||
help_message = cliobj.get_help(ctx).replace(ctx.command_path, cmd)
|
||||
|
||||
if cliobj.name == "cli":
|
||||
|
@ -43,25 +43,26 @@ def iter_commands(
|
|||
else:
|
||||
cmd_title = cliobj.name
|
||||
|
||||
yield f"{'#'*(depth)} {cmd_title}\n```\n{help_message}\n```"
|
||||
yield f"{'#'*(depth)} {name} {cmd_title}\n```\n{help_message}\n```"
|
||||
|
||||
|
||||
def generate_usage_md(script: str, version: str):
|
||||
name, module = script
|
||||
assert ":" in script
|
||||
module, cliobj = script.split(":")
|
||||
if "." in module:
|
||||
module_name = module.split(".")[0]
|
||||
module_name, cliobj = module.split(":")
|
||||
if "." in module_name:
|
||||
module_name = module_name.split(".")[0]
|
||||
else:
|
||||
module_name = module
|
||||
module_name = module_name
|
||||
|
||||
mod = importlib.import_module(module)
|
||||
mod = importlib.import_module(module_name)
|
||||
cli = getattr(mod, cliobj)
|
||||
|
||||
with open("USAGE.md", "wt") as fd:
|
||||
print(
|
||||
f"# {module_name.capitalize()} v{version} - Command Usage Overview", file=fd
|
||||
f"# {module_name.capitalize()} v{version} - {name} - Command Usage Overview", file=fd
|
||||
)
|
||||
for command in iter_commands(module_name, [], cli):
|
||||
for command in iter_commands(name, [], cli):
|
||||
print(command, file=fd)
|
||||
|
||||
|
||||
|
@ -80,7 +81,7 @@ def cli():
|
|||
def run(ctx, poetry_project_file):
|
||||
contents = toml.loads(poetry_project_file.read())
|
||||
try:
|
||||
scripts = contents["tool"]["poetry"]["scripts"]
|
||||
scripts = contents["tool"]["poetry"]["scripts"].items()
|
||||
version = contents["tool"]["poetry"]["version"]
|
||||
for script in scripts.values():
|
||||
generate_usage_md(script, version)
|
||||
|
|
Loading…
Reference in New Issue