From 7da8988205833cb56e9506b7598fbb738a6a4def Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 17 Sep 2023 20:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E5=81=9A=E4=B8=80=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=8F=91=E4=B8=8A=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib_not_dr/nuitka/compile.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib_not_dr/nuitka/compile.py b/lib_not_dr/nuitka/compile.py index 3e1d95a..81ef42d 100644 --- a/lib_not_dr/nuitka/compile.py +++ b/lib_not_dr/nuitka/compile.py @@ -7,10 +7,40 @@ import platform import warnings from pathlib import Path -from typing import List, Tuple, Optional +from typing import List, Tuple, Optional, Union from lib_not_dr.types import Options, Version, VersionRequirement + +def ensure_cmd_readable(cmd: str) -> str: + """ + 保证 参数中 不含空格 + :param cmd: 要格式化的命令行参数 + :return: 格式化后的命令行参数 + """ + if ' ' in cmd: + return f'"{cmd}"' + return cmd + + +def format_cmd(arg_name: Optional[str], arg_value: Optional[Union[str, List[str]]]) -> List[str]: + """ + 用来格式化输出命令行参数 + :param arg_name: 类似 --show-memory 之类的主项 + :param arg_value: 类似 xxx 类的内容 + :return: 直接拼接好的命令行参数 不带 = + """ + if arg_name is None: + return [] + if arg_value is None: + return [arg_name] + if isinstance(arg_value, list): + arg_value = ','.join([ensure_cmd_readable(value) for value in arg_value]) + return [f'{arg_name}{arg_value}'] + arg_value = ensure_cmd_readable(arg_value) + return [f'{arg_name}{arg_value}'] + + def _add_cmd(cmd: List[str], string: Optional[str]) -> List[str]: if string is not None and string: cmd.append(string)