Skip to content

Commit

Permalink
feat: allow boj open command run without id
Browse files Browse the repository at this point in the history
We can get the problem id from .boj-info.json in case that we run `boj
open` in the problem directory.
  • Loading branch information
xvzc committed Jan 20, 2024
1 parent ee9128c commit 539ca34
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions boj/args_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
16 changes: 14 additions & 2 deletions boj/commands/open/open_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
1 change: 0 additions & 1 deletion boj/commands/run/run_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 539ca34

Please sign in to comment.