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:
+4
-12
@@ -3,9 +3,10 @@
|
||||
dir="$(find_problem "$1")"
|
||||
old="$(detect_io "$dir" || true)"
|
||||
if [[ $# -lt 2 ]]; then
|
||||
stdio="$(grep -o 'STDIO("[^"]*")' "$dir/main.cpp" 2>/dev/null | sed 's/STDIO("\(.*\)")/\1/' | head -1 || true)"
|
||||
wired="$(show_io "$dir" || true)"
|
||||
echo "lang: $(lang_of "$dir")"
|
||||
echo "files: ${old:-none}"
|
||||
echo "STDIO: ${stdio:-none}"
|
||||
echo "source: ${wired:-none}"
|
||||
exit 0
|
||||
fi
|
||||
io="$2"
|
||||
@@ -16,14 +17,5 @@ if [[ -n "$old" && "$old" != "$io" ]]; then
|
||||
done
|
||||
fi
|
||||
[[ -e "$dir/$io.in" ]] || { touch "$dir/$io.in"; echo "Created $io.in"; }
|
||||
# rewire STDIO in main.cpp
|
||||
if grep -q 'STDIO("' "$dir/main.cpp" 2>/dev/null; then
|
||||
sed -i "s/STDIO(\"[^\"]*\")/STDIO(\"$io\")/" "$dir/main.cpp"
|
||||
echo "Updated STDIO(\"$io\") in main.cpp"
|
||||
elif grep -q '^int main() {$' "$dir/main.cpp" 2>/dev/null; then
|
||||
sed -i "s/^int main() {$/int main() {\n STDIO(\"$io\");/" "$dir/main.cpp"
|
||||
echo "Inserted STDIO(\"$io\") in main.cpp"
|
||||
else
|
||||
echo "Warning: couldn't find STDIO(...) or 'int main() {' in main.cpp — wire it up manually" >&2
|
||||
fi
|
||||
wire_io "$dir" "$io"
|
||||
echo "io name for $(basename "$dir") is now '$io'"
|
||||
|
||||
Reference in New Issue
Block a user