Skip to content

Commit

Permalink
Merge pull request #172 from fukatani/language-match
Browse files Browse the repository at this point in the history
feature: select submit language by name
  • Loading branch information
kmyk authored Jul 29, 2018
2 parents b10e5cd + 3c96c33 commit 55b63ef
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions onlinejudge/implementation/command/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,24 @@ def submit(args):
with utils.with_cookiejar(utils.new_default_session(), path=args.cookie) as sess:
# language
langs = problem.get_language_dict(session=sess)

if args.language not in langs:
log.error('language is unknown')
log.info('supported languages are:')
for lang in sorted(langs.keys()):
log.emit('%s (%s)', lang, langs[lang]['description'])
sys.exit(1)
matched_language = search_matched_language(args.language, langs)
if len(matched_language) == 1:
args.language = matched_language[0]
log.info('choosed language: %s', matched_language)
elif not matched_language:
log.error('language is unknown')
log.info('supported languages are:')
for lang in sorted(langs.keys()):
log.emit('%s (%s)', lang, langs[lang]['description'])
sys.exit(1)
else:
log.error('Matched languages were not narrowed down to one.')
log.info('You have to choose:')
for lang in sorted(matched_language):
log.emit('%s', lang)
sys.exit(1)

# confirm
if args.wait:
Expand Down Expand Up @@ -75,3 +87,12 @@ def submit(args):
else:
log.info('open the submission page with: %s', args.open)
subprocess.check_call([ args.open, submission.get_url() ], stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)

def search_matched_language(language, language_dict):
# Search partial matched language name (not case sensitive)

matched_language = []
for supported_lang in language_dict.values():
if language.lower() in supported_lang['description'].lower():
matched_language.append(supported_lang['description'])
return matched_language

0 comments on commit 55b63ef

Please sign in to comment.