Command line interface for BOJ


Keywords
baekjoon, baekjoon-online-judge, boj, cli, command-line-interface, command-line-tool
License
MIT
Install
pip install boj-cli==1.2.3

Documentation

boj-cli

BOJ-CLI


Command line interface for Baekjoon Online Judge.

boj-cli demo

Table of contents

Requirements

  • Python <= 3.11
  • MacOS, Linux, Windows

Installation

$ pip install boj-cli

Configuration

# ~/myproject/.boj/config.yaml
general:
  selenium_browser: "chrome"        # required - firefox | chrome | edge
  default_filetype: "cpp"           # optional - default filetype for 'boj add'
  editor_command: "nvim -o"         # required - code | nvim | ..
workspace:
  ongoing_dir: "problems"           # optional - ongoing problem directory. default: ""
  archive_dir: "archives"           # optional - archive directory.         default: "archives"
filetype:
  py:
    language: "python3"             # required - language  for your submission
    main: "main.py"                 # required - the main file name
    run: "python3 $file"            # required - the run command
  cpp:
    language: "c++17"
    main: "main.cpp"
    source_templates:               # optional - these files will be copied into source dir
      - "main.cpp"
    root_templates:                 # optional - these files will be copied into root dir
      - "compile_flags.txt"
    compile: "g++ -std=c++17 $file" # optional - set this option if you use compile language
    run: "./a.out"
    after: "rm -rf a.out"           # optional - command to execute after 'boj run'
    # other filetypes ..

filetype.language์— ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š” ๊ฐ’๋“ค์€ Supported languages๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

Usage

usage: boj [-h] [-v] {init,add,login,open,random,run,submit,clean,case} ...

positional arguments:
  {init,add,login,open,random,run,submit,clean,case}
    init                initializes BOJ directory
    add                 sets up an environment of the given problem id
    login               logs in to BOJ
    open                opens a problem of given id in browser
    random              queries and opens a random problem in browser
    run                 runs generated testcases
    submit              submit your solution and trace the realtime statement
    clean               archives accepted source files
    case                manages testcases

options:
  -h, --help            show this help message and exit
  -v, --version         show version

init

$ boj init

ํ˜„์žฌ ๊ฒฝ๋กœ๋ฅผ BOJ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์„ค์ •ํ•˜๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฆฌ์†Œ์Šค๋“ค์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

  • ./.boj
  • ./.boj/config.yaml
  • ./.boj/templates

login

$ boj login

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€์—์„œ๋Š” ๋กœ๊ทธ์ธ ์‹œ reCAPTCHA๋ฅผ ์‚ฌ์šฉํ•˜๊ณ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋กœ๊ทธ์ธ ๊ณผ์ •์€ ์กฐ๊ธˆ ๋ฒˆ๊ฑฐ๋กœ์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์œ„ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด selenium ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์‹คํ–‰๋˜๊ณ , reCAPTCHA๋ฅผ ํฌํ•จํ•œ ๋กœ๊ทธ์ธ์„ ์ˆ˜ํ–‰ํ•˜๋ฉด ์„ธ์…˜ ์ •๋ณด๋ฅผ ๋กœ์ปฌ ๋””๋ ‰ํ† ๋ฆฌ $HOME/.boj-cli์— ์•”ํ˜ธํ™”ํ•ด์„œ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

๋กœ๊ทธ์ธ ์‹œ "๋กœ๊ทธ์ธ ์ƒํƒœ ์œ ์ง€" ์ฒดํฌ ๋ฐ•์Šค๋ฅผ ๋ฐ˜๋“œ์‹œ ์„ ํƒํ•ด์ฃผ์„ธ์š”.


add

$ boj add 1234 -f cpp
Testcases have been created.

$ tree .
โ”œโ”€โ”€ 1234
โ”‚ย ย  โ”œโ”€โ”€ compile_flags.txt
โ”‚ย ย  โ”œโ”€โ”€ main.cpp
โ”‚ย ย  โ””โ”€โ”€ testcases
โ”‚ย ย      โ”œโ”€โ”€ 1
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ input.txt
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ output.txt
โ”‚ย ย      โ”œโ”€โ”€ 2
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ input.txt
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ output.txt
โ”‚ย ย      โ”œโ”€โ”€ 3
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ input.txt
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ output.txt
โ”‚ย ย      โ”œโ”€โ”€ 4
โ”‚ย ย      โ”‚ย ย  โ”œโ”€โ”€ input.txt
โ”‚ย ย      โ”‚ย ย  โ””โ”€โ”€ output.txt
โ”‚ย ย      โ””โ”€โ”€ 5
โ”‚ย ย          โ”œโ”€โ”€ input.txt
โ”‚ย ย          โ””โ”€โ”€ output.txt
โ””โ”€โ”€ .boj 
    โ”œโ”€โ”€ config.yaml
    โ””โ”€โ”€ templates
        โ”œโ”€โ”€ compile_flags.txt
        โ””โ”€โ”€ main.cpp

๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€ ๋ฌธ์ œ๋ฅผ ํ’€๊ธฐ์œ„ํ•œ ํด๋”๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ž‘์—…๋“ค์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ./.boj/templates ํด๋”์— ์œ„์น˜ํ•œ ํ…œํ”Œ๋ฆฟ ํŒŒ์ผ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ.
  • ํฌ๋กค๋ง์„ ํ™œ์šฉํ•ด์„œ ํ…์ŠคํŠธ๋กœ ํŒŒ์‹ฑํ•œ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค ํŒŒ์ผ ์ƒ์„ฑ.
--type, -t str: ํŒŒ์ผ ํƒ€์ž…์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. (e.g. cpp, ts, rs, py ...)
(์ด ์˜ต์…˜์€ 'config.general.default_filetype'์„ override ํ•ฉ๋‹ˆ๋‹ค.)
--force, -f: ์ด๋ฏธ ๋ฌธ์ œ๊ฐ€ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋„ ๋ฎ์–ด์”๋‹ˆ๋‹ค.

run

# Outside of problem dir
$ boj run 1234

# Inside of problem dir
$ cd 1234 && boj run

testcases ๊ฒฝ๋กœ์— ์žˆ๋Š” ๋ชจ๋“  ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋ฅผ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ  ์ •๋‹ต์„ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ ํด๋” ์•ˆ์—์„œ ์‹คํ–‰ํ•˜๋ฉด ๋ฌธ์ œ ๋ฒˆํ˜ธ ์ธ์ž๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

--timeout int(sec): ๊ฐ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์˜ ํƒ€์ž„์•„์›ƒ์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค (default: 10์ดˆ)

submit

# Outside of problem directory
$ boj submit 1234

# Inside of problem directory
$ cd 1234 && boj run

๋กœ์ปฌ ์†Œ์Šค ํŒŒ์ผ์„ ๋ฐฑ์ค€ ์˜จ๋ผ์ธ ์ €์ง€์— ์ œ์ถœํ•˜๊ณ  ์ฑ„์  ํ˜„ํ™ฉ์„ ์‹ค์‹œ๊ฐ„์œผ๋กœ ๊ตฌ๋…ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ ํด๋” ์•ˆ์—์„œ ์‹คํ–‰ํ•˜๋ฉด ๋ฌธ์ œ ๋ฒˆํ˜ธ ์ธ์ž๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

--open [ 'open' | 'close' | 'onlyaccepted' ]: ์ฝ”๋“œ ๊ณต๊ฐœ ์—ฌ๋ถ€๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. default: 'onlyaccepted'
--timeout int: ์ œ์ถœ ํ˜„ํ™ฉ ์›น์†Œ์ผ“์˜ ํƒ€์ž„์•„์›ƒ ์„ค์ •(์ดˆ) (default: 10)

clean

$ boj clean

boj submit ๋ช…๋ น์–ด ์ˆ˜ํ–‰ ๊ฒฐ๊ณผ๋กœ accepted๋ฅผ ๋ฐ›์€ ๋ชจ๋“  ๋ฌธ์ œ๋“ค์„ config.workspace.archive_dir๋กœ ์•„์นด์ด๋ธŒํž™๋‹ˆ๋‹ค.

์•„์นด์ด๋ธŒ ๋˜๋Š” ํŒŒ์ผ์€ yyyymmdd_hhmmss_{filename}์˜ ํฌ๋ฉง์œผ๋กœ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. ๋งˆ์ง€๋ง‰ ์ œ์ถœ ์ดํ›„์— ๋ณ€๊ฒฝ๋œ ์†Œ์Šค ์ฝ”๋“œ์— ๋Œ€ํ•ด์„œ๋Š” ์•„์นด์ด๋น™์„ ์ˆ˜ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

--origin, -o: ์•„์นด์ด๋ธŒ ํŒŒ์ผ ํฌ๋ฉง์„ ๋ฌด์‹œํ•˜๊ณ  ์›๋ณธ ํŒŒ์ผ ์ด๋ฆ„์„ ์‚ฌ์šฉํ•˜๋ฉฐ, ํŒŒ์ผ ์ด๋ฆ„์ด ์ด๋ฏธ ์กด์žฌํ•˜๋ฉด ๋ฎ์–ด์”๋‹ˆ๋‹ค.

open

# Outside of problem directory
$ boj open 1234

# Inside of problem directory
$ cd 1234 && boj open

๊ธฐ๋ณธ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋ฌธ์ œ ๋ฒˆํ˜ธ์— ํ•ด๋‹นํ•˜๋Š” ํŽ˜์ด์ง€์˜ ๋งํฌ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ ํด๋” ์•ˆ์—์„œ ์‹คํ–‰ํ•˜๋ฉด ๋ฌธ์ œ ๋ฒˆํ˜ธ ์ธ์ž๋ฅผ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


random

$ boj random --tier g1..g5 --tags dp math

solvedac API๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ฌธ์ œ๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ , ๊ธฐ๋ณธ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋งํฌ๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.

์—ฌ๋Ÿฌ๊ฐœ์˜ tags ์˜ต์…˜์€ 'OR' ์กฐ๊ฑด์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.
'๋‚ด๊ฐ€ ํ’€์ง€ ์•Š์€ ๋ฌธ์ œ' ๋งŒ ์ฟผ๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

--tier, -i: ๋ฌธ์ œ ํ‹ฐ์–ด ์ฟผ๋ฆฌ
--tags, -t: ๋ฌธ์ œ ํƒœ๊ทธ ์ฟผ๋ฆฌ

case

$ boj case -e 1
$ boj case -n 

config.general.editor_command ๊ฐ’์„ ์ฐธ์กฐํ•˜์—ฌ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

--edit $TESTCASE_ID, -e $TESTACSE_ID: ์ฃผ์–ด์ง„ id์— ํ•ด๋‹นํ•˜๋Š” ํ…Œ์ŠคํŠธ์ผ€์ด์Šค ํŒŒ์ผ๋“ค์„ ํŽธ์ง‘ํ•ฉ๋‹ˆ๋‹ค.
--new, -n: ์ƒˆ๋กœ์šด ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํŽธ์ง‘ํ•ฉ๋‹ˆ๋‹ค. TESTCASE_ID๋Š” ์ž๋™๋ถ€์—ฌ ๋ฉ๋‹ˆ๋‹ค.

Supported languages

c++17 python3 pypy3 c99 c11 text golfscript java8 c++98 ruby
c++11 java11 kotlin(jvm) c++14 swift java8(openjdk) c++20 c#
node.js go d rust2018 go(gccgo) c++17(clang) java15 d(ldc) php
rust2015 pascal lua perl f# visual-basic objective-c c99(clang)
c++98(clang) c++11(clang) c++14(clang) objective-c++ c11(clang) c90
c90(clang) c2x(clang) typescript c++20(clang) bash fortran scheme
awk c2x assembly(32bit) assembly(64bit) o-caml whitespace lolcode
intercal rhino cobol pike sed tcl brainf**k ada system-verilog
algol68 befunge haxe ์•„ํฌ bc free-basic rust2021 scala