From be3e4876062c05c03505d08929aea273b7abfbbd Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sat, 21 Jan 2023 07:44:55 +0000 Subject: [PATCH] :sparkles: add nested plugin prompt --- nb_cli/cli/commands/plugin.py | 14 ++++++-- nb_cli/locale/zh_CN/LC_MESSAGES/nb-cli.po | 40 +++++++++++++---------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/nb_cli/cli/commands/plugin.py b/nb_cli/cli/commands/plugin.py index 0cb9fb2..ceeacbf 100644 --- a/nb_cli/cli/commands/plugin.py +++ b/nb_cli/cli/commands/plugin.py @@ -2,7 +2,7 @@ from typing import List, Optional, cast import click -from noneprompt import Choice, ListPrompt, InputPrompt, CancelledError +from noneprompt import Choice, ListPrompt, InputPrompt, ConfirmPrompt, CancelledError from nb_cli import _ from nb_cli.config import GLOBAL_CONFIG @@ -163,7 +163,7 @@ async def uninstall( @plugin.command(aliases=["new"], help=_("Create a new nonebot plugin.")) @click.argument("name", nargs=1, required=False, default=None) -@click.option("-s", "--sub-plugin", is_flag=True, default=False) +@click.option("-s", "--sub-plugin", is_flag=True, default=None) @click.option( "-o", "--output-dir", @@ -176,7 +176,7 @@ async def uninstall( async def create( ctx: click.Context, name: Optional[str], - sub_plugin: bool, + sub_plugin: Optional[bool], output_dir: Optional[str], template: Optional[str], ): @@ -187,6 +187,14 @@ async def create( ) except CancelledError: ctx.exit() + if sub_plugin is None: + try: + sub_plugin = await ConfirmPrompt( + _("Use nested plugin?"), default_choice=False + ).prompt_async(style=CLI_DEFAULT_STYLE) + except CancelledError: + ctx.exit() + if output_dir is None: detected: List[Choice[None]] = [ Choice(str(d)) for d in Path(".").glob("**/plugins/") if d.is_dir() diff --git a/nb_cli/locale/zh_CN/LC_MESSAGES/nb-cli.po b/nb_cli/locale/zh_CN/LC_MESSAGES/nb-cli.po index 6baee45..16e63cd 100644 --- a/nb_cli/locale/zh_CN/LC_MESSAGES/nb-cli.po +++ b/nb_cli/locale/zh_CN/LC_MESSAGES/nb-cli.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: nb-cli 1.0.0\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2023-01-18 09:46+0000\n" +"POT-Creation-Date: 2023-01-21 07:41+0000\n" "PO-Revision-Date: 2023-01-11 08:56+0000\n" "Last-Translator: FULL NAME \n" "Language: zh_Hans_CN\n" @@ -46,7 +46,7 @@ msgstr "欢迎使用 NoneBot CLI!" msgid "What do you want to do?" msgstr "你想要进行什么操作?" -#: nb_cli/cli/commands/project.py:294 nb_cli/cli/customize.py:109 +#: nb_cli/cli/commands/project.py:296 nb_cli/cli/customize.py:109 msgid "The working directory." msgstr "工作目录." @@ -123,16 +123,16 @@ msgid "Where to store the adapter?" msgstr "请输入适配器存储的位置:" #: nb_cli/cli/commands/adapter.py:199 nb_cli/cli/commands/adapter.py:202 -#: nb_cli/cli/commands/plugin.py:197 nb_cli/cli/commands/plugin.py:200 +#: nb_cli/cli/commands/plugin.py:205 nb_cli/cli/commands/plugin.py:208 msgid "Other" msgstr "其他" #: nb_cli/cli/commands/adapter.py:204 nb_cli/cli/commands/adapter.py:213 -#: nb_cli/cli/commands/plugin.py:202 nb_cli/cli/commands/plugin.py:211 +#: nb_cli/cli/commands/plugin.py:210 nb_cli/cli/commands/plugin.py:219 msgid "Output Dir:" msgstr "输出目录:" -#: nb_cli/cli/commands/adapter.py:210 nb_cli/cli/commands/plugin.py:208 +#: nb_cli/cli/commands/adapter.py:210 nb_cli/cli/commands/plugin.py:216 msgid "Output dir is not a directory!" msgstr "输出目录不是一个文件夹!" @@ -236,7 +236,11 @@ msgstr "使用的插件模板." msgid "Plugin name:" msgstr "插件名称:" -#: nb_cli/cli/commands/plugin.py:197 nb_cli/cli/commands/project.py:126 +#: nb_cli/cli/commands/plugin.py:193 +msgid "Use nested plugin?" +msgstr "使用嵌套插件?" + +#: nb_cli/cli/commands/plugin.py:205 nb_cli/cli/commands/project.py:126 msgid "Where to store the plugin?" msgstr "请输入插件存储位置:" @@ -308,53 +312,53 @@ msgstr "创建虚拟环境?" msgid "Creating virtual environment in {venv_dir} ..." msgstr "在 {venv_dir} 中创建虚拟环境..." -#: nb_cli/cli/commands/project.py:238 +#: nb_cli/cli/commands/project.py:240 msgid "Which builtin plugin(s) would you like to use?" msgstr "要使用哪些内置插件?" -#: nb_cli/cli/commands/project.py:251 +#: nb_cli/cli/commands/project.py:253 msgid "Failed to add builtin plugins {builtin_plugins} to config: {e}" msgstr "添加内置插件 {builtin_plugins} 到配置文件失败: {e}" -#: nb_cli/cli/commands/project.py:258 +#: nb_cli/cli/commands/project.py:260 msgid "Done!" msgstr "完成!" -#: nb_cli/cli/commands/project.py:260 +#: nb_cli/cli/commands/project.py:262 msgid "" "Add following packages to your project using dependency manager like " "poetry or pdm:" msgstr "使用 poetry 或 pdm 等依赖管理工具添加以下包:" -#: nb_cli/cli/commands/project.py:266 +#: nb_cli/cli/commands/project.py:268 msgid "Run the following command to start your bot:" msgstr "运行以下命令来启动你的机器人:" -#: nb_cli/cli/commands/project.py:277 +#: nb_cli/cli/commands/project.py:279 msgid "Generate entry file of your bot." msgstr "生成机器人的入口文件." -#: nb_cli/cli/commands/project.py:283 +#: nb_cli/cli/commands/project.py:285 msgid "The file script saved to." msgstr "脚本文件保存路径." -#: nb_cli/cli/commands/project.py:292 +#: nb_cli/cli/commands/project.py:294 msgid "Run the bot in current folder." msgstr "在当前文件夹中运行机器人." -#: nb_cli/cli/commands/project.py:300 +#: nb_cli/cli/commands/project.py:302 msgid "Exist entry file of your bot." msgstr "存在的机器人入口文件." -#: nb_cli/cli/commands/project.py:307 +#: nb_cli/cli/commands/project.py:309 msgid "Reload the bot when file changed." msgstr "当文件发生变化时重新加载机器人." -#: nb_cli/cli/commands/project.py:313 +#: nb_cli/cli/commands/project.py:315 msgid "Files to watch for changes." msgstr "要监视变化的文件." -#: nb_cli/cli/commands/project.py:319 +#: nb_cli/cli/commands/project.py:321 msgid "Files to ignore for changes." msgstr "要忽略变化的文件."