From 10990c45f6598d0b8dddc0f7837620b002047e89 Mon Sep 17 00:00:00 2001 From: JohnserfSeed Date: Fri, 5 Jan 2024 21:24:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88bool=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E9=BB=98=E8=AE=A4=E5=80=BC=EF=BC=8C=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=8Ecli=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=86=B2=E7=AA=81=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #22 https://github.com/Johnserf-Seed/TikTokDownload/issues/632#issuecomment-1877992815 https://github.com/Johnserf-Seed/TikTokDownload/issues/626 --- f2/apps/douyin/cli.py | 16 +++++++++++----- f2/apps/tiktok/cli.py | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/f2/apps/douyin/cli.py b/f2/apps/douyin/cli.py index 723360b8..4bb28543 100644 --- a/f2/apps/douyin/cli.py +++ b/f2/apps/douyin/cli.py @@ -353,13 +353,19 @@ def douyin(ctx, config, init_config, update_config, **kwargs): app_config = manager.get_config("douyin", {}) # 合并配置文件的值到kwargs - for key, value in app_config.items(): + for config_key, config_value in app_config.items(): # 在命令的参数列表中找到当前的键 - param = next((p for p in ctx.command.params if p.name == key), None) + param = next((p for p in ctx.command.params if p.name == config_key), None) if param: - default_value = param.default # 获取默认值 - if ctx.params[key] == default_value: # 如果命令行参数等于默认值 - kwargs[key] = value # 使用配置文件的值覆盖默认值 + # 如果命令行参数没有提供值,则使用配置文件的值 + if ctx.params[config_key] is None or ctx.params[config_key] == "": + kwargs[config_key] = config_value + else: + kwargs[config_key] = ctx.params[config_key] + + logger.info(_("配置文件路径: {0}".format(config))) + logger.debug(_("配置文件参数: {0}".format(app_config))) + logger.debug(_("配置文件与CLI合并后的参数: {0}".format(kwargs))) # 如果指定了update_config,更新配置文件 if update_config: diff --git a/f2/apps/tiktok/cli.py b/f2/apps/tiktok/cli.py index 849d3803..f86f26e1 100644 --- a/f2/apps/tiktok/cli.py +++ b/f2/apps/tiktok/cli.py @@ -308,13 +308,19 @@ def tiktok(ctx, config, init_config, update_config, **kwargs): app_config = manager.get_config("tiktok", {}) # 合并配置文件的值到kwargs - for key, value in app_config.items(): + for config_key, config_value in app_config.items(): # 在命令的参数列表中找到当前的键 - param = next((p for p in ctx.command.params if p.name == key), None) + param = next((p for p in ctx.command.params if p.name == config_key), None) if param: - default_value = param.default # 获取默认值 - if ctx.params[key] == default_value: # 如果命令行参数等于默认值 - kwargs[key] = value # 使用配置文件的值覆盖默认值 + # 如果命令行参数没有提供值,则使用配置文件的值 + if ctx.params[config_key] is None or ctx.params[config_key] == "": + kwargs[config_key] = config_value + else: + kwargs[config_key] = ctx.params[config_key] + + logger.info(_("配置文件路径: {0}".format(config))) + logger.debug(_("配置文件参数: {0}".format(app_config))) + logger.debug(_("配置文件与CLI合并后的参数: {0}".format(kwargs))) # 如果指定了update_config,更新配置文件 if update_config: