change output comment

This commit is contained in:
elpekenin 2024-10-06 10:37:34 +02:00
parent 6f7b8da5b5
commit 01d6ac79fa

View File

@ -138,13 +138,13 @@ def _render_image_metadata(metadata):
return "\n".join(lines) return "\n".join(lines)
def generate_command_str(cli, command_name): def command_args_str(cli, command_name):
"""Given a command name, introspect milc to get the arguments passed in.""" """Given a command name, introspect milc to get the arguments passed in."""
args = [] args = {}
max_length = 0
for arg_name, was_passed in cli.args_passed[command_name].items(): for arg_name, was_passed in cli.args_passed[command_name].items():
# we might ignore a value if it was not passed in max_length = max(max_length, len(arg_name))
# but not doing so (for now?)
val = getattr(cli.args, arg_name.replace("-", "_")) val = getattr(cli.args, arg_name.replace("-", "_"))
@ -152,19 +152,19 @@ def generate_command_str(cli, command_name):
if isinstance(val, Path): if isinstance(val, Path):
val = val.name val = val.name
args.append(f"--{arg_name} {val}") args[arg_name] = val
command_name = command_name.replace("_", "-") return "\n".join(
args_str = " ".join(args) f"// {arg_name.ljust(max_length)} | {val}"
for arg_name, val in args.items()
return f"qmk {command_name} {args_str}" )
def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, command_name): def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, command_name):
if font_metadata is not None and image_metadata is not None: if font_metadata is not None and image_metadata is not None:
raise ValueError("Cant generate subs for font and image at the same time") raise ValueError("Cant generate subs for font and image at the same time")
command = generate_command_str(cli, command_name) args = command_args_str(cli, command_name)
subs = { subs = {
"year": datetime.date.today().strftime("%Y"), "year": datetime.date.today().strftime("%Y"),
@ -173,7 +173,8 @@ def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, co
"byte_count": len(out_bytes), "byte_count": len(out_bytes),
"bytes_lines": render_bytes(out_bytes), "bytes_lines": render_bytes(out_bytes),
"format": cli.args.format, "format": cli.args.format,
"generator_command": command, "generator_command": command_name.replace("_", "-"),
"command_args": args,
} }
if font_metadata is not None: if font_metadata is not None:
@ -192,7 +193,7 @@ def generate_subs(cli, out_bytes, *, font_metadata=None, image_metadata=None, co
subs.update({ subs.update({
"generated_type": "image", "generated_type": "image",
"var_prefix": "gfx", "var_prefix": "gfx",
"generator_command": command, "generator_command": command_name,
"metadata": _render_image_metadata(image_metadata), "metadata": _render_image_metadata(image_metadata),
}) })
@ -208,7 +209,8 @@ license_template = """\
// Copyright ${year} QMK -- generated source code only, ${generated_type} retains original copyright // Copyright ${year} QMK -- generated source code only, ${generated_type} retains original copyright
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// This file was auto-generated by `${generator_command}` // This file was auto-generated by `${generator_command}` with arguments:
${command_args}
""" """