|
1 | 1 | #!/usr/bin/python3
|
2 | 2 | import argparse
|
| 3 | +from os.path import expanduser |
3 | 4 |
|
4 | 5 | from atcodertools.executils.run_command import run_command_with_returncode
|
5 | 6 | from atcodertools.tools.models.metadata import Metadata
|
6 | 7 | from atcodertools.common.language import Language
|
7 | 8 | import os
|
8 | 9 | import pathlib
|
| 10 | +from atcodertools.config.config import Config, ConfigType |
| 11 | +from atcodertools.tools import get_default_config_path |
| 12 | + |
| 13 | +USER_CONFIG_PATH = os.path.join(expanduser("~"), ".atcodertools.toml") |
9 | 14 |
|
10 | 15 |
|
11 | 16 | class BadStatusCodeException(Exception):
|
@@ -56,13 +61,40 @@ def main(prog, args):
|
56 | 61 |
|
57 | 62 | parser.add_argument('--compile-only-when-diff-detected',
|
58 | 63 | help='compile only when diff detected [true, false]'
|
59 |
| - ' [Default]: true', |
| 64 | + ' [Default]: false', |
60 | 65 | type=bool,
|
61 |
| - default=False) |
| 66 | + default=None) |
| 67 | + |
| 68 | + parser.add_argument("--config", |
| 69 | + help="File path to your config file\n{0}{1}".format("[Default (Primary)] {}\n".format( |
| 70 | + USER_CONFIG_PATH), |
| 71 | + "[Default (Secondary)] {}\n".format( |
| 72 | + get_default_config_path())), |
| 73 | + default=None) |
62 | 74 |
|
63 | 75 | args = parser.parse_args(args)
|
| 76 | + if args.config is None: |
| 77 | + if os.path.exists(USER_CONFIG_PATH): |
| 78 | + args.config = USER_CONFIG_PATH |
| 79 | + else: |
| 80 | + args.config = get_default_config_path() |
64 | 81 |
|
65 | 82 | metadata = Metadata.load_from("./metadata.json")
|
66 |
| - force_compile = not args.compile_only_when_diff_detected |
| 83 | + lang = metadata.lang |
| 84 | + |
| 85 | + with open(args.config, "r") as f: |
| 86 | + config = Config.load(f, {ConfigType.COMPILER}, args, lang.name) |
| 87 | + |
| 88 | + if args.compile_only_when_diff_detected: |
| 89 | + force_compile = not args.compile_only_when_diff_detected |
| 90 | + else: |
| 91 | + force_compile = not config.compiler_config.compile_only_when_diff_detected |
| 92 | + |
| 93 | + if args.compile_command: |
| 94 | + compile_command = args.compile_command |
| 95 | + else: |
| 96 | + compile_command = config.compiler_config.compile_command |
| 97 | + if compile_command: |
| 98 | + compile_command = lang.get_compile_command("main", compile_command) |
67 | 99 | compile_main_and_judge_programs(metadata.lang, force_compile=force_compile,
|
68 |
| - compile_command=args.compile_command) |
| 100 | + compile_command=compile_command) |
0 commit comments