Tidy the usaco CLI: prefixes everywhere, LOCAL debug builds, git-based dates

- done/skip/undo accept unique prefixes like every other command
- builds define LOCAL (-I repo root): the template includes debugging.h
  and enables DBG/printV only locally, so main.cpp is submittable as-is
- run/build/test --debug (or USACO_DEBUG=1): ASan/UBSan + _GLIBCXX_DEBUG
- list/stats date problems by git history, not mtimes reset by checkouts
- template/tpl is now an alias of reset (which gains -y); fixes template
  dropping the STDIO line
- run shows <io>.out via detect_io instead of the first *.out
- debugging.h: size_t loop indices (no -Wsign-compare noise)
- zsh completion for i/cat/copy; README covers test, io, reset, --debug
- ignore a.out

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 22:39:16 +01:00
co-authored by Claude Opus 5.5
parent 1c647072c5
commit ac66ad6b03
18 changed files with 118 additions and 54 deletions
+1
View File
@@ -8,3 +8,4 @@ skipped/*/main
.current .current
.usaco_history .usaco_history
.current_stack .current_stack
a.out
+19 -5
View File
@@ -33,7 +33,19 @@ Creates `solving/<name>/main.cpp` from the template and an empty `.in` file, the
./usaco run diamond-collector # compile + run, then print the .out file ./usaco run diamond-collector # compile + run, then print the .out file
./usaco build diamond-collector # compile only ./usaco build diamond-collector # compile only
``` ```
Compiles with `g++ -O2 -std=c++17 -Wall -Wextra` and runs inside the problem dir so file IO just works. Put your test input in the `.in` file first. Compiles with `g++ -O2 -std=c++17 -Wall -Wextra -DLOCAL` and runs inside the problem dir so file IO just works. Put your test input in the `.in` file first.
Add `--debug` to `run`, `build` or `test` (or set `USACO_DEBUG=1`) for a sanitizer build (`-fsanitize=address,undefined`, `_GLIBCXX_DEBUG`): out-of-bounds indexing, overflow and other UB crash with a stack trace instead of silently giving wrong answers.
**Debug output:** `LOCAL` is only defined by `./usaco` builds, so the template's `#ifdef LOCAL #include "debugging.h"` (pretty-printers for vectors, maps, pairs…) and its `DBG(x)` macros vanish on the judge — submit `main.cpp` as-is.
### Test cases
```
./usaco test create diamond-collector # save tests/N.in (current .in, or paste) + expected N.out
./usaco test diamond-collector # build, run every saved case, diff, show pass/fail + time
./usaco test diamond-collector 2 3 # only cases 2 and 3
```
Diffs ignore trailing whitespace and trailing blank lines. A case with no `.out` just prints what it produced.
### Finish (or give up on) a problem ### Finish (or give up on) a problem
``` ```
@@ -48,15 +60,15 @@ The website commits too: marking a problem solved/skipped, or editing its link o
### Edit ### Edit
``` ```
./usaco vim diamond-collector # open main.cpp in $EDITOR (defaults to vim) ./usaco vim diamond-collector # open main.cpp in $EDITOR (defaults to nvim)
./usaco e diamond-collector # same thing, shorter (also: edit) ./usaco e diamond-collector # same thing, shorter (also: edit)
``` ```
Opens from inside the problem dir, so the `.in`/`.out` files are right there. Opens from inside the problem dir, so the `.in`/`.out` files are right there.
### Look around ### Look around
``` ```
./usaco list # all problems by status, oldest-touched first ./usaco list # all problems by status, oldest-touched first (by last commit; uncommitted work counts as newest)
./usaco stats # counts + problems solved in the last 7 / 30 days ./usaco stats # counts + problems solved in the last 7 / 30 days (by the commit that moved them to solved/)
./usaco open diamond-collector # open the saved problem URL in a browser ./usaco open diamond-collector # open the saved problem URL in a browser
``` ```
@@ -88,7 +100,9 @@ The selection persists across sessions in `.current` (cleared automatically if t
### Misc ### Misc
``` ```
./usaco template diamond-collector # reset main.cpp from template (old one saved as main.cpp.bak) ./usaco reset diamond-collector # fresh main.cpp from template (old one -> main.cpp.bak), delete binary + .out
# asks first (-y skips); keeps tests/ and .in (aliases: template, rm)
./usaco io diamond-collector # show the io name; 'io <name> <new>' renames .in/.out and rewires STDIO
./usaco clean # delete compiled binaries (main, a.out) and .bak files everywhere ./usaco clean # delete compiled binaries (main, a.out) and .bak files everywhere
./usaco path diamond-collector # print the problem's directory ./usaco path diamond-collector # print the problem's directory
``` ```
+3 -3
View File
@@ -36,7 +36,7 @@ std::ostream &operator<<(std::ostream &out, const std::vector<T> &vec) {
return out; return out;
} }
out << '['; out << '[';
for (int i = 0; i < vec.size() - 1; i++) { for (size_t i = 0; i < vec.size() - 1; i++) {
out << vec[i] << ", "; out << vec[i] << ", ";
} }
return out << vec.back() << ']'; return out << vec.back() << ']';
@@ -49,7 +49,7 @@ std::ostream &operator<<(std::ostream &out, const std::array<T, SZ> &arr) {
return out; return out;
} }
out << '['; out << '[';
for (int i = 0; i < SZ - 1; i++) { for (size_t i = 0; i < SZ - 1; i++) {
out << arr[i] << ", "; out << arr[i] << ", ";
} }
return out << arr.back() << ']'; return out << arr.back() << ']';
@@ -62,7 +62,7 @@ std::ostream &operator<<(std::ostream &out, const std::deque<T> &deq) {
return out; return out;
} }
out << '['; out << '[';
for (int i = 0; i < deq.size() - 1; i++) { for (size_t i = 0; i < deq.size() - 1; i++) {
out << deq[i] << ", "; out << deq[i] << ", ";
} }
return out << deq.back() << ']'; return out << deq.back() << ']';
+2 -2
View File
@@ -1,7 +1,7 @@
# usaco done <name> # usaco done <name>
[[ $# -ge 1 ]] || usage [[ $# -ge 1 ]] || usage
name="$1" dir="$(find_problem "$1")"; name="$(basename "$dir")"
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; } [[ "$dir" == "$ROOT/solving/$name" ]] || { echo "Error: $name is not in solving/ (it's in ${dir#$ROOT/})" >&2; exit 1; }
[[ -d "$ROOT/solved/$name" ]] && { echo "Error: solved/$name already exists" >&2; exit 1; } [[ -d "$ROOT/solved/$name" ]] && { echo "Error: solved/$name already exists" >&2; exit 1; }
mv "$ROOT/solving/$name" "$ROOT/solved/$name" mv "$ROOT/solving/$name" "$ROOT/solved/$name"
echo "Moved to solved/$name 🎉" echo "Moved to solved/$name 🎉"
+3 -3
View File
@@ -8,7 +8,7 @@ STACK_FILE="$ROOT/.current_stack"
HISTFILE="$ROOT/.usaco_history" HISTFILE="$ROOT/.usaco_history"
# commands that take a problem name (the selection is injected when you omit it) # 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 template reset" WITH_PROBLEM="run build test done undo skip io cat copy edit open path reset"
# commands that take no problem # commands that take no problem
NO_PROBLEM="list stats clean sync" NO_PROBLEM="list stats clean sync"
# REPL-only words (used for completion and for 'help') # REPL-only words (used for completion and for 'help')
@@ -144,7 +144,7 @@ while :; do
case "$c" in case "$c" in
r) c=run ;; b) c=build ;; t) c=test ;; d) c=done ;; u) c=undo ;; sk) c=skip ;; r) c=run ;; b) c=build ;; t) c=test ;; d) c=done ;; u) c=undo ;; sk) c=skip ;;
e|vim) c=edit ;; o) c=open ;; l|ls) c=list ;; st) c=stats ;; p) c=path ;; e|vim) c=edit ;; o) c=open ;; l|ls) c=list ;; st) c=stats ;; p) c=path ;;
tpl) c=template ;; rm|delete) c=reset ;; cp) c=copy ;; sy) c=sync ;; tpl|template|rm|delete) c=reset ;; cp) c=copy ;; sy) c=sync ;;
esac esac
if [[ " $NO_PROBLEM " == *" $c "* ]]; then if [[ " $NO_PROBLEM " == *" $c "* ]]; then
@@ -155,7 +155,7 @@ while :; do
if [[ " $WITH_PROBLEM " == *" $c "* ]]; then if [[ " $WITH_PROBLEM " == *" $c "* ]]; then
# 'test create' keeps its subword first; the name goes after it # '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 pre=(); if [[ "$c" == test && "${args[0]:-}" =~ ^(create|add|new)$ ]]; then pre=("${args[0]}"); args=("${args[@]:1}"); fi
if [[ ${#args[@]} -ge 1 ]]; then # explicit name: use it and switch to it if [[ ${#args[@]} -ge 1 && "${args[0]}" != -* ]]; then # explicit name: use it and switch to it
n="$(real_name "${args[0]}")" || { find_problem "${args[0]}" >/dev/null || true; continue; } n="$(real_name "${args[0]}")" || { find_problem "${args[0]}" >/dev/null || true; continue; }
set_current "$n"; args=("${args[@]:1}") set_current "$n"; args=("${args[@]:1}")
elif [[ -z "$cur" ]]; then elif [[ -z "$cur" ]]; then
+1 -2
View File
@@ -3,8 +3,7 @@ list_by_mtime() { # list subdirs of $1 oldest-first by last modification
[[ -d "$1" ]] || return 0 [[ -d "$1" ]] || return 0
for d in "$1"/*/; do for d in "$1"/*/; do
[[ -d "$d" ]] || continue [[ -d "$d" ]] || continue
# newest mtime of any file in the problem dir printf '%s\t%s\n' "$(last_touched "${d%/}")" "$(basename "$d")"
printf '%s\t%s\n' "$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1)" "$(basename "$d")"
done | sort -n | cut -f2 | sed 's/^/ /' done | sort -n | cut -f2 | sed 's/^/ /'
} }
echo "== Solving ==" echo "== Solving =="
+8 -6
View File
@@ -1,14 +1,16 @@
# usaco reset/rm/delete <name> # usaco reset/rm/delete/template/tpl <name> [-y]
[[ $# -ge 1 ]] || usage [[ $# -ge 1 ]] || usage
dir="$(find_problem "$1")" dir="$(find_problem "$1")"
name="$(basename "$dir")" name="$(basename "$dir")"
io="$(detect_io "$dir" || true)" io="$(detect_io "$dir" || true)"
io="${io:-$name}" io="${io:-$name}"
echo "This resets ${dir#$ROOT/} to a fresh template:" if [[ "${2:-}" != -y ]]; then
echo " main.cpp -> re-created from template (old one saved as main.cpp.bak)" echo "This resets ${dir#$ROOT/} to a fresh template:"
echo " removes compiled binary and $io.out (tests/ and $io.in are kept)" echo " main.cpp -> re-created from template (old one saved as main.cpp.bak)"
read -r -p "Reset '$name'? [y/N] " ans echo " removes compiled binary and $io.out (tests/ and $io.in are kept)"
[[ "$ans" == y || "$ans" == Y ]] || { echo "Aborted."; exit 1; } read -r -p "Reset '$name'? [y/N] " ans
[[ "$ans" == y || "$ans" == Y ]] || { echo "Aborted."; exit 1; }
fi
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak" [[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak"
fresh_main "$dir" "$io" fresh_main "$dir" "$io"
rm -f "$dir/main" "$dir/a.out" "$dir/$io.out" rm -f "$dir/main" "$dir/a.out" "$dir/$io.out"
+4 -4
View File
@@ -5,8 +5,8 @@ build_problem "$dir"
# run from inside the dir so freopen finds the .in file # run from inside the dir so freopen finds the .in file
(cd "$dir" && ./main) (cd "$dir" && ./main)
# show the .out file if the program wrote one # show the .out file if the program wrote one
out="$(ls "$dir"/*.out 2>/dev/null | grep -v '/a\.out$' | head -1 || true)" io="$(detect_io "$dir" || true)"
if [[ -n "$out" ]]; then if [[ -n "$io" && -f "$dir/$io.out" ]]; then
echo "── $(basename "$out") ──" echo "── $io.out ──"
cat "$out" cat "$dir/$io.out"
fi fi
+2 -2
View File
@@ -1,7 +1,7 @@
# usaco skip <name> # usaco skip <name>
[[ $# -ge 1 ]] || usage [[ $# -ge 1 ]] || usage
name="$1" dir="$(find_problem "$1")"; name="$(basename "$dir")"
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; } [[ "$dir" == "$ROOT/solving/$name" ]] || { echo "Error: $name is not in solving/ (it's in ${dir#$ROOT/})" >&2; exit 1; }
[[ -d "$ROOT/skipped/$name" ]] && { echo "Error: skipped/$name already exists" >&2; exit 1; } [[ -d "$ROOT/skipped/$name" ]] && { echo "Error: skipped/$name already exists" >&2; exit 1; }
mkdir -p "$ROOT/skipped" mkdir -p "$ROOT/skipped"
mv "$ROOT/solving/$name" "$ROOT/skipped/$name" mv "$ROOT/solving/$name" "$ROOT/skipped/$name"
+1 -1
View File
@@ -5,7 +5,7 @@ now=$(date +%s); week=0; month=0
if [[ -d "$ROOT/solved" ]]; then if [[ -d "$ROOT/solved" ]]; then
for d in "$ROOT/solved"/*/; do for d in "$ROOT/solved"/*/; do
[[ -d "$d" ]] || continue [[ -d "$d" ]] || continue
t="$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1)" t="$(solved_at "${d%/}")"
[[ -z "$t" ]] && continue [[ -z "$t" ]] && continue
age=$(( now - t )) age=$(( now - t ))
(( age <= 7*86400 )) && week=$((week+1)) (( age <= 7*86400 )) && week=$((week+1))
-6
View File
@@ -1,6 +0,0 @@
# usaco template/tpl <name>
[[ $# -ge 1 ]] || usage
dir="$(find_problem "$1")"
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak" && echo "Backed up old main.cpp -> main.cpp.bak"
cp "$ROOT/template.cpp" "$dir/main.cpp"
echo "Refreshed $dir/main.cpp from template"
+3 -5
View File
@@ -1,10 +1,8 @@
# usaco undo <name> # usaco undo <name>
[[ $# -ge 1 ]] || usage [[ $# -ge 1 ]] || usage
name="$1"; from="" dir="$(find_problem "$1")"; name="$(basename "$dir")"
for s in solved skipped; do from="$(basename "$(dirname "$dir")")"
[[ -d "$ROOT/$s/$name" ]] && from="$s" && break [[ "$from" != solving ]] || { echo "Error: $name is already in solving/" >&2; exit 1; }
done
[[ -n "$from" ]] || { echo "Error: '$name' not found in solved/ or skipped/" >&2; exit 1; }
[[ -d "$ROOT/solving/$name" ]] && { echo "Error: solving/$name already exists" >&2; exit 1; } [[ -d "$ROOT/solving/$name" ]] && { echo "Error: solving/$name already exists" >&2; exit 1; }
mv "$ROOT/$from/$name" "$ROOT/solving/$name" mv "$ROOT/$from/$name" "$ROOT/solving/$name"
echo "Moved back to solving/$name (was $from)" echo "Moved back to solving/$name (was $from)"
+29 -2
View File
@@ -1,7 +1,10 @@
# common.sh - shared helpers for usaco commands (sourced, not executed) # common.sh - shared helpers for usaco commands (sourced, not executed)
# Expects ROOT to be set by the dispatcher. # Expects ROOT to be set by the dispatcher.
CXXFLAGS=(-O2 -std=c++17 -Wall -Wextra) # -DLOCAL turns on the template's debugging.h include and DBG macros (judges don't define it)
CXXFLAGS=(-O2 -std=c++17 -Wall -Wextra -DLOCAL -I"$ROOT")
# --debug (or USACO_DEBUG=1): catch out-of-bounds, overflow and UB at runtime
DEBUG_CXXFLAGS=(-g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -D_GLIBCXX_DEBUG)
find_problem() { # echoes dir of problem in solving/, solved/, or skipped/; unique prefix ok find_problem() { # echoes dir of problem in solving/, solved/, or skipped/; unique prefix ok
local name="$1" s d matches=() local name="$1" s d matches=()
@@ -24,7 +27,12 @@ find_problem() { # echoes dir of problem in solving/, solved/, or skipped/; uni
} }
build_problem() { # $1 = problem dir build_problem() { # $1 = problem dir
g++ "${CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main" if [[ -n "${USACO_DEBUG:-}" ]]; then
echo "${DIM}(debug build: sanitizers on)${RST}" >&2
g++ "${CXXFLAGS[@]}" "${DEBUG_CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main"
else
g++ "${CXXFLAGS[@]}" "$1/main.cpp" -o "$1/main"
fi
} }
detect_io() { # echoes the io basename (first *.in in $1), or nothing detect_io() { # echoes the io basename (first *.in in $1), or nothing
@@ -33,6 +41,25 @@ detect_io() { # echoes the io basename (first *.in in $1), or nothing
return 1 return 1
} }
last_touched() { # $1 = problem dir: epoch of its last change
# uncommitted work counts as "now"-ish (newest mtime); otherwise the last commit.
# File mtimes alone are useless here: every checkout/pull resets them.
local t
if [[ -n "$(git -C "$ROOT" status --porcelain -- "$1" 2>/dev/null)" ]]; then
find "$1" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1
elif t="$(git -C "$ROOT" log -1 --format=%ct -- "$1" 2>/dev/null)" && [[ -n "$t" ]]; then
echo "$t"
else
find "$1" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1
fi
}
solved_at() { # $1 = solved/<name> dir: epoch it (last) entered solved/
local t
t="$(git -C "$ROOT" log -1 --diff-filter=A --format=%ct -- "$1" 2>/dev/null)"
[[ -n "$t" ]] && echo "$t" || last_touched "$1"
}
fresh_main() { # $1 = problem dir, $2 = io name: main.cpp from template with STDIO wired up fresh_main() { # $1 = problem dir, $2 = io name: main.cpp from template with STDIO wired up
sed "s/^int main() {$/int main() {\n STDIO(\"$2\");/" "$ROOT/template.cpp" > "$1/main.cpp" sed "s/^int main() {$/int main() {\n STDIO(\"$2\");/" "$ROOT/template.cpp" > "$1/main.cpp"
} }
+6 -2
View File
@@ -4,7 +4,9 @@
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <vector> #include <vector>
#include "../../debugging.h" #ifdef LOCAL
#include "debugging.h"
#endif
using namespace std; using namespace std;
// ----- FILE IO ----- // ----- FILE IO -----
@@ -81,7 +83,9 @@ int main() {
} }
} }
cerr << seen ; #ifdef LOCAL
cerr << seen;
#endif
cout << maxRes << NL; cout << maxRes << NL;
return 0; return 0;
} }
+3 -1
View File
@@ -1,4 +1,6 @@
#include "../../debugging.h" #ifdef LOCAL
#include "debugging.h"
#endif
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
+11 -1
View File
@@ -1,5 +1,8 @@
#include <bits/stdc++.h> #include <bits/stdc++.h>
using namespace std; using namespace std;
#ifdef LOCAL // set by ./usaco builds only, so this is safe to submit as-is
#include "debugging.h"
#endif
// ----- TYPES ----- // ----- TYPES -----
@@ -65,11 +68,18 @@ typedef vector<int> vi;
// ----- OUTPUT ----- // ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL #define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG ----- // ----- DEBUG ----- (compiled out on the judge)
#ifdef LOCAL
#define DBG(vari) cerr << #vari << " = " << (vari) << endl #define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl #define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ') #define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1) #define printV(a) printA(a, 0, SZ(a) - 1)
#else
#define DBG(vari)
#define DBG2(a, b)
#define printA(a, L, R)
#define printV(a)
#endif
// ----- STL DS // ----- STL DS
#define ALL(c) (c).begin(), (c).end() #define ALL(c) (c).begin(), (c).end()
+13 -6
View File
@@ -28,18 +28,19 @@
# usaco path <name> Print the problem's directory (used by the ucd shell helper) # usaco path <name> Print the problem's directory (used by the ucd shell helper)
# usaco clean Delete compiled binaries and backups from all problem dirs # usaco clean Delete compiled binaries and backups from all problem dirs
# usaco sync git pull --rebase (picks up edits made on the website), then push # usaco sync git pull --rebase (picks up edits made on the website), then push
# usaco template <name> Re-copy template.cpp into the problem as main.cpp (backs up old one) # usaco reset <name> [-y] Reset the solution: fresh main.cpp from template (STDIO wired up,
# usaco reset <name> Reset the solution: fresh main.cpp from template (STDIO wired up), # old one saved as main.cpp.bak), delete binary + .out; keeps tests/
# delete binary + .out; keeps tests/ and .in (aliases: rm, delete) # and .in. Asks first unless -y (aliases: rm, delete, template, tpl)
# usaco test create <name> Save a test case: uses the current .in (or lets you paste one), # usaco test create <name> Save a test case: uses the current .in (or lets you paste one),
# then asks for the expected output. Stored in tests/N.in + N.out # then asks for the expected output. Stored in tests/N.in + N.out
# usaco test <name> [nums...] Build and run every saved test case (or just the given ones), # usaco test <name> [nums...] Build and run every saved test case (or just the given ones),
# diff against expected output, show pass/fail # diff against expected output, show pass/fail
# #
# Short aliases: n=new r=run b=build t=test d=done u=undo sk=skip o=open # Short aliases: n=new r=run b=build t=test d=done u=undo sk=skip o=open
# l/ls=list st=stats p=path tpl=template e=edit=vim sy=sync # l/ls=list st=stats p=path e=edit=vim sy=sync
# #
# Names may be unique prefixes: 'usaco e diam' finds diamond-collector. # Names may be unique prefixes: 'usaco e diam' finds diamond-collector.
# run/build/test take --debug: build with sanitizers (-fsanitize=address,undefined).
# #
# Implementation: each command lives in lib/cmd/<name>.sh; shared helpers in lib/common.sh. # Implementation: each command lives in lib/cmd/<name>.sh; shared helpers in lib/common.sh.
@@ -68,10 +69,16 @@ case "$cmd" in
path|p) cmd=path ;; path|p) cmd=path ;;
clean) cmd=clean ;; clean) cmd=clean ;;
sync|sy) cmd=sync ;; sync|sy) cmd=sync ;;
template|tpl) cmd=template ;; reset|rm|delete|template|tpl) cmd=reset ;;
reset|rm|delete) cmd=reset ;;
*) usage ;; *) usage ;;
esac esac
# --debug may appear anywhere in the arguments
args=()
for a in "$@"; do
if [[ "$a" == --debug ]]; then export USACO_DEBUG=1; else args+=("$a"); fi
done
set -- "${args[@]+"${args[@]}"}"
source "$ROOT/lib/common.sh" source "$ROOT/lib/common.sh"
source "$ROOT/lib/cmd/$cmd.sh" source "$ROOT/lib/cmd/$cmd.sh"
+9 -3
View File
@@ -24,6 +24,9 @@ _usaco_problems() {
_usaco() { _usaco() {
local -a cmds local -a cmds
cmds=( cmds=(
'i:interactive mode (REPL with a current problem)'
'interactive:interactive mode (REPL with a current problem)'
'repl:interactive mode (REPL with a current problem)'
'new:create a problem from template' 'new:create a problem from template'
'n:create a problem from template' 'n:create a problem from template'
'run:build and run main.cpp' 'run:build and run main.cpp'
@@ -42,6 +45,9 @@ _usaco() {
'skip:set aside for later' 'skip:set aside for later'
'sk:set aside for later' 'sk:set aside for later'
'io:show or set the freopen io name' 'io:show or set the freopen io name'
'cat:print main.cpp to stdout'
'copy:copy main.cpp to the clipboard'
'cp:copy main.cpp to the clipboard'
'open:open the saved problem URL' 'open:open the saved problem URL'
'o:open the saved problem URL' 'o:open the saved problem URL'
'list:list problems by status' 'list:list problems by status'
@@ -54,8 +60,8 @@ _usaco() {
'clean:delete binaries and backups' 'clean:delete binaries and backups'
'sync:pull website edits, push local commits' 'sync:pull website edits, push local commits'
'sy:pull website edits, push local commits' 'sy:pull website edits, push local commits'
'template:re-copy template.cpp as main.cpp (backs up old)' 'template:same as reset'
'tpl:re-copy template.cpp as main.cpp (backs up old)' 'tpl:same as reset'
'reset:fresh main.cpp from template, delete binary/.out' 'reset:fresh main.cpp from template, delete binary/.out'
'rm:fresh main.cpp from template, delete binary/.out' 'rm:fresh main.cpp from template, delete binary/.out'
'delete:fresh main.cpp from template, delete binary/.out' 'delete:fresh main.cpp from template, delete binary/.out'
@@ -64,7 +70,7 @@ _usaco() {
_describe 'command' cmds _describe 'command' cmds
elif (( CURRENT == 3 )); then elif (( CURRENT == 3 )); then
case "$words[2]" in case "$words[2]" in
new|n|list|l|ls|stats|st|clean|sync|sy) ;; # no problem-name argument i|interactive|repl|new|n|list|l|ls|stats|st|clean|sync|sy) ;; # no problem-name argument
test|t) test|t)
local -a subs local -a subs
subs=('create:save a new test case' 'add:save a new test case' 'new:save a new test case') subs=('create:save a new test case' 'add:save a new test case' 'new:save a new test case')