Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions nb_cli/handlers/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ def draw_logo() -> str:
return figlet_format("NoneBot", font="basic").strip()


def get_nonebot_config() -> NoneBotConfig | LegacyNoneBotConfig:
return GLOBAL_CONFIG.get_nonebot_config()
def get_config_manager(cwd: Path | None = None) -> ConfigManager:
return ConfigManager(working_dir=cwd) if cwd is not None else GLOBAL_CONFIG


def get_nonebot_config(cwd: Path | None = None) -> NoneBotConfig | LegacyNoneBotConfig:
config = get_config_manager(cwd)
return config.get_nonebot_config()


def get_project_root(cwd: Path | None = None) -> Path:
config = ConfigManager(working_dir=cwd) if cwd is not None else GLOBAL_CONFIG
config = get_config_manager(cwd)
return config.project_root


Expand Down Expand Up @@ -90,7 +95,7 @@ async def _get_env_python() -> str:


async def get_default_python(cwd: Path | None = None) -> str:
config = ConfigManager(working_dir=cwd) if cwd is not None else GLOBAL_CONFIG
config = get_config_manager(cwd)
if config.python_path is not None:
return config.python_path

Expand Down
18 changes: 10 additions & 8 deletions nb_cli/handlers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from nb_cli import _
from nb_cli.config import (
GLOBAL_CONFIG,
SimpleInfo,
PackageInfo,
NoneBotConfig,
Expand All @@ -23,6 +22,7 @@
from .meta import (
get_project_root,
requires_nonebot,
get_config_manager,
get_default_python,
get_nonebot_config,
requires_project_root,
Expand Down Expand Up @@ -127,8 +127,8 @@ def _index_by_module_name(data: Iterable[T_info]) -> dict[str, T_info]:


@requires_project_root
async def upgrade_project_format() -> None:
bot_config = get_nonebot_config()
async def upgrade_project_format(*, cwd: Path | None = None) -> None:
bot_config = get_nonebot_config(cwd)
if isinstance(bot_config, NoneBotConfig):
click.echo(_("Current format is already the new format."))
return
Expand Down Expand Up @@ -178,13 +178,14 @@ async def upgrade_project_format() -> None:
builtin_plugins=bot_config.builtin_plugins,
)

GLOBAL_CONFIG.update_nonebot_config(new_config)
GLOBAL_CONFIG.update_dependency(nonebot_pkg, *packages)
manager = get_config_manager(cwd)
manager.update_nonebot_config(new_config)
manager.update_dependency(nonebot_pkg, *packages)


@requires_project_root
async def downgrade_project_format() -> None:
bot_config = get_nonebot_config()
async def downgrade_project_format(*, cwd: Path | None = None) -> None:
bot_config = get_nonebot_config(cwd)
if isinstance(bot_config, LegacyNoneBotConfig):
click.echo(_("Current format is already the old format."))
return
Expand All @@ -196,4 +197,5 @@ async def downgrade_project_format() -> None:
builtin_plugins=bot_config.builtin_plugins,
)

GLOBAL_CONFIG.update_nonebot_config(old_config)
manager = get_config_manager(cwd)
manager.update_nonebot_config(old_config)