Skip to content

Commit

Permalink
✨ add nested plugin prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Jan 21, 2023
1 parent 0f0d1d0 commit be3e487
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
14 changes: 11 additions & 3 deletions nb_cli/cli/commands/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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],
):
Expand All @@ -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()
Expand Down
40 changes: 22 additions & 18 deletions nb_cli/locale/zh_CN/LC_MESSAGES/nb-cli.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 <EMAIL@ADDRESS>\n"
"Language: zh_Hans_CN\n"
Expand Down Expand Up @@ -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 "工作目录."

Expand Down Expand Up @@ -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 "输出目录不是一个文件夹!"

Expand Down Expand Up @@ -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 "请输入插件存储位置:"

Expand Down Expand Up @@ -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 "要忽略变化的文件."

Expand Down

0 comments on commit be3e487

Please sign in to comment.