# usaco new [io-name] [--url ] [--rust|--cpp] | usaco new [[ $# -ge 1 ]] || usage name=""; io=""; url=""; lang="" while [[ $# -gt 0 ]]; do case "$1" in --url) url="${2:-}"; shift 2 ;; --lang|-l) lang="$(normalize_lang "${2:-}")" || exit 1; shift 2 ;; --rust|--rs) lang=rust; shift ;; --cpp|--c++) lang=cpp; shift ;; *) 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. # Always C++, whatever 'usaco lang' says: the driver is C++. if [[ "$name" == daily || "$name" =~ ^(https?://)?(www\.)?leetcode\.com/problems/ ]]; then [[ "${lang:-cpp}" == cpp ]] || { echo "Error: LeetCode imports are C++ only" >&2; exit 1; } 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}" lang="${lang:-$(default_lang)}" 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" "$lang" touch "$dir/$io.in" [[ -n "$url" ]] && echo "$url" > "$dir/.url" [[ -n "${USACO_CREATED:-}" ]] && printf '%s\n' "$name" > "$USACO_CREATED" src="$(src_name "$lang")" echo "Created solving/$name/$src (io: $io.in / $io.out)" [[ "$lang" == rust ]] && sync_cargo_manifest >/dev/null (cd "$dir" && exec ${EDITOR:-nvim} "$src")