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]>
40 lines
1.7 KiB
Bash
40 lines
1.7 KiB
Bash
# usaco reset/rm/delete/template/tpl <name> [cpp|rust] [-y]
|
|
[[ $# -ge 1 ]] || usage
|
|
dir="$(find_problem "$1")"; shift
|
|
name="$(basename "$dir")"
|
|
yes=""; lang=""
|
|
for a in "$@"; do
|
|
if [[ "$a" == -y ]]; then yes=1; else lang="$(normalize_lang "$a")" || exit 1; fi
|
|
done
|
|
lang="${lang:-$(lang_of "$dir" 2>/dev/null || default_lang)}"
|
|
leet=""; [[ -f "$dir/driver.h" ]] && leet=1
|
|
if [[ -n "$leet" && "$lang" != cpp ]]; then
|
|
echo "Error: $name is a LeetCode import, and those are C++ only" >&2; exit 1
|
|
fi
|
|
io="$(detect_io "$dir" || true)"
|
|
io="${io:-$name}"
|
|
old="$(main_file "$dir" 2>/dev/null || true)"
|
|
src="$(src_name "$lang")"
|
|
if [[ -z "$yes" ]]; then
|
|
echo "This resets ${dir#$ROOT/} to a fresh $lang template:"
|
|
if [[ -n "$leet" ]]; then
|
|
echo " $src -> LeetCode's starter code again (old one saved as $src.bak)"
|
|
else
|
|
echo " $src -> re-created from template (old one saved as $(basename "${old:-$src}").bak)"
|
|
fi
|
|
echo " removes compiled binary and $io.out (tests/ and $io.in are kept)"
|
|
read -r -p "Reset '$name'? [y/N] " ans
|
|
[[ "$ans" == y || "$ans" == Y ]] || { echo "Aborted."; exit 1; }
|
|
fi
|
|
[[ -n "$old" && -f "$old" ]] && cp "$old" "$old.bak"
|
|
# switching language: drop the old source so lang_of stays unambiguous
|
|
[[ -n "$old" && "$(basename "$old")" != "$src" ]] && rm -f "$old"
|
|
if [[ -n "$leet" ]]; then # a LeetCode import: re-fetch its starter code
|
|
python3 -I "$ROOT/lib/leetcode.py" "$ROOT" "$dir" --main-only >/dev/null || exit 1
|
|
else
|
|
fresh_main "$dir" "$io" "$lang"
|
|
fi
|
|
[[ "$lang" == rust || "$old" == *.rs ]] && sync_cargo_manifest >/dev/null
|
|
rm -f "$dir/main" "$dir/a.out" "$dir/$io.out"
|
|
echo "Reset $name (old solution in $(basename "${old:-$src}").bak)"
|