# usaco new [io-name] [--url ] | usaco new [[ $# -ge 1 ]] || usage name=""; io=""; url="" while [[ $# -gt 0 ]]; do case "$1" in --url) url="${2:-}"; shift 2 ;; *) if [[ -z "$name" ]]; then name="$1"; elif [[ -z "$io" ]]; then io="$1"; fi; shift ;; esac done [[ -n "$name" ]] || usage # A LeetCode link (or "daily": today's daily question) imports the problem: # statement, starter code, a generated driver, and the examples as tests. if [[ "$name" == daily || "$name" =~ ^(https?://)?(www\.)?leetcode\.com/problems/ ]]; then name="$(python3 -I "$ROOT/lib/leetcode.py" "$ROOT" "$name")" || exit 1 [[ -n "${USACO_CREATED:-}" ]] && printf '%s\n' "$name" > "$USACO_CREATED" echo "Created solving/$name (statement in problem.md; 'usaco t $name' runs the examples)" (cd "$ROOT/solving/$name" && exec ${EDITOR:-nvim} main.cpp) exit fi io="${io:-$name}" dir="$ROOT/solving/$name" if [[ -d "$dir" || -d "$ROOT/solved/$name" || -d "$ROOT/skipped/$name" ]]; then echo "Error: '$name' already exists" >&2; exit 1 fi mkdir -p "$dir" fresh_main "$dir" "$io" touch "$dir/$io.in" [[ -n "$url" ]] && echo "$url" > "$dir/.url" [[ -n "${USACO_CREATED:-}" ]] && printf '%s\n' "$name" > "$USACO_CREATED" echo "Created solving/$name (io: $io.in / $io.out)" (cd "$dir" && exec ${EDITOR:-nvim} main.cpp)