Add Rust support: usaco lang, lint, and main.rs problems

Brings in the stashed Rust work, merged onto the current CLI. A
problem's language is whichever source it has (main.cpp or main.rs);
'usaco lang' sets the default for new problems (.lang, or $USACO_LANG),
and 'new --rust/--cpp' picks per problem. template.rs is a paste-ready
Rust template whose stdio() uses <io>.in/.out when present and
stdin/stdout otherwise.

run/test now feed <io>.in on stdin and capture stdout when the program
doesn't write <io>.out itself, so Codeforces-style solutions work too.
'reset <name> rust|cpp' switches a problem's language (template is
still an alias), and --debug builds Rust with overflow checks and debug
assertions. 'usaco lint' runs clippy through a generated, gitignored
Cargo.toml that also gives rust-analyzer a project; done/skip/undo
keep it in step. LeetCode imports stay C++.

Also: done stages solved/ and solving/ separately, so a problem that
was never committed from solving/ still gets its "Solve" commit, and
the site lists main.rs ahead of other files like it does main.cpp.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 21:17:50 +01:00
co-authored by Claude Opus 5.5
parent e821df15f4
commit 1aee0050a0
24 changed files with 588 additions and 112 deletions
+13 -4
View File
@@ -10,7 +10,7 @@ HISTFILE="$ROOT/.usaco_history"
# commands that take a problem name (the selection is injected when you omit it)
WITH_PROBLEM="run build test done undo skip io cat copy edit open path reset"
# commands that take no problem
NO_PROBLEM="list stats clean sync"
NO_PROBLEM="list stats clean sync lang"
# REPL-only words (used for completion and for 'help')
REPL_WORDS="s use none push pop stack help quit exit"
@@ -70,7 +70,8 @@ ${DIM}selection${RST}
${DIM}problem commands${RST} ${DIM}(name optional — omit it to use the selection; giving one switches to it)${RST}
$WITH_PROBLEM
${DIM}other${RST}
$NO_PROBLEM, new <name>, new <leetcode-url|daily>
$NO_PROBLEM, new <name> [io] [--rust|--cpp], new <leetcode-url|daily>
lint [<name>] clippy the selection, or every rust solution
help [<cmd>] this, or the dispatcher's usage line for <cmd>
!cmd run a shell command in the problem dir
q quit
@@ -83,7 +84,7 @@ _usaco_comp() { # completes REPL commands and problem names
for d in "$ROOT"/solving/*/ "$ROOT"/solved/*/ "$ROOT"/skipped/*/; do names+=("$(basename "$d")"); done
shopt -u nullglob
if [[ $COMP_CWORD -eq 0 ]]; then
COMPREPLY=($(compgen -W "$WITH_PROBLEM $NO_PROBLEM $REPL_WORDS new ${names[*]}" -- "$w"))
COMPREPLY=($(compgen -W "$WITH_PROBLEM $NO_PROBLEM $REPL_WORDS new lint ${names[*]}" -- "$w"))
else
COMPREPLY=($(compgen -W "${names[*]}" -- "$w"))
fi
@@ -141,6 +142,12 @@ while :; do
if USACO_CREATED="$created" "$ROOT/usaco" new "${args[@]}"; then set_current "$(<"$created")"; fi
rm -f "$created"
continue ;;
lint)
# the one command whose problem name is optional: it lints the
# selection if there is one, otherwise every rust solution
[[ ${#args[@]} -eq 0 && -n "$cur" ]] && args=("$cur")
"$ROOT/usaco" lint "${args[@]+"${args[@]}"}" || true
continue ;;
esac
# expand short aliases to full names so the tables below match
@@ -158,7 +165,9 @@ while :; do
if [[ " $WITH_PROBLEM " == *" $c "* ]]; then
# 'test create' keeps its subword first; the name goes after it
pre=(); if [[ "$c" == test && "${args[0]:-}" =~ ^(create|add|new)$ ]]; then pre=("${args[0]}"); args=("${args[@]:1}"); fi
if [[ ${#args[@]} -ge 1 && "${args[0]}" != -* ]]; then # explicit name: use it and switch to it
# 'reset rust' switches the selection's language: a language word isn't a name
lang_arg=""; [[ "$c" == reset ]] && normalize_lang "${args[0]:-}" >/dev/null 2>&1 && lang_arg=1
if [[ ${#args[@]} -ge 1 && "${args[0]}" != -* && -z "$lang_arg" ]]; then # explicit name: use it and switch to it
n="$(real_name "${args[0]}")" || { find_problem "${args[0]}" >/dev/null || true; continue; }
set_current "$n"; args=("${args[@]:1}")
elif [[ -z "$cur" ]]; then