From 539ca3434e39e568ccb7f8041cc01d8d4aac76d6 Mon Sep 17 00:00:00 2001 From: xvzc Date: Sat, 20 Jan 2024 17:43:20 +0900 Subject: [PATCH] feat: allow boj open command run without id We can get the problem id from .boj-info.json in case that we run `boj open` in the problem directory. --- boj/args_resolver.py | 2 ++ boj/commands/open/open_command.py | 16 ++++++++++++++-- boj/commands/run/run_command.py | 1 - 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/boj/args_resolver.py b/boj/args_resolver.py index 14e2caf..5737c49 100644 --- a/boj/args_resolver.py +++ b/boj/args_resolver.py @@ -66,6 +66,8 @@ def add_open_parser(subparsers): problem_parser.add_argument( "problem_id", metavar="PROBLEM_ID", + default=None, + nargs='?', type=int, help="problem id", ) diff --git a/boj/commands/open/open_command.py b/boj/commands/open/open_command.py index 8acf6ca..72733d7 100644 --- a/boj/commands/open/open_command.py +++ b/boj/commands/open/open_command.py @@ -2,12 +2,24 @@ import boj.core.constant from boj.core.base import Command -from boj.core.config import Config from boj.core.out import BojConsole +from boj.core.config import Config +from boj.data.boj_info import BojInfo class OpenCommand(Command): def execute(self, args): console = BojConsole() with console.status("Opening in browser..."): - webbrowser.open(boj.core.constant.boj_problem_url(args.problem_id)) + problem_id = None + if args.problem_id: + problem_id = args.problem_id + else: + config = Config.load() + boj_info = BojInfo.find_any( + problem_dir=config.workspace.problem_dir, + problem_id=None + ) + problem_id = boj_info.id + + webbrowser.open(boj.core.constant.boj_problem_url(problem_id)) diff --git a/boj/commands/run/run_command.py b/boj/commands/run/run_command.py index f7b5642..5298b41 100644 --- a/boj/commands/run/run_command.py +++ b/boj/commands/run/run_command.py @@ -5,7 +5,6 @@ from boj.core.config import Config from boj.core.out import BojConsole from boj.data.boj_info import BojInfo -from boj.core.error import IllegalStatementError, ResourceNotFoundError from boj.data.solution import Solution from boj.data.testcase import TomlTestcase