Add a CLI guide page to the website
/usaco/cli summarises the ./usaco commands, setup, a typical session and interactive mode, linked from the header. It's a hand-written copy of the README (the Docker build context is site/, so it can't import it). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
# USACO site
|
||||
|
||||
The public face of this repo, served at `/usaco/` on adam-french.co.uk. It shows the solved problems: each solution, its sample input, saved tests and notes, and its git history, plus a stats page with a solve calendar. When the site's admin is logged in, it also shows problems in `solving/` and `skipped/`, and lets them:
|
||||
The public face of this repo, served at `/usaco/` on adam-french.co.uk. It shows the solved problems: each solution, its sample input, saved tests and notes, and its git history, plus a stats page with a solve calendar and a guide to the `./usaco` CLI. When the site's admin is logged in, it also shows problems in `solving/` and `skipped/`, and lets them:
|
||||
|
||||
- mark a problem solved, skipped or back in progress
|
||||
- set its link
|
||||
@@ -49,7 +49,7 @@ Everything is served under `BASE_PATH` (`/usaco`). nginx proxies the prefix thro
|
||||
|
||||
| Path | Auth | What |
|
||||
|---|---|---|
|
||||
| `/usaco/`, `/usaco/p/<name>`, `/usaco/stats` | none | SPA |
|
||||
| `/usaco/`, `/usaco/p/<name>`, `/usaco/stats`, `/usaco/cli` | none | SPA |
|
||||
| `GET /usaco/api/problems` | open; the admin also gets unsolved problems | the list |
|
||||
| `GET /usaco/api/problems/<name>` | open for solved problems; 404 for others unless admin | one problem, with files, tests and history |
|
||||
| `GET /usaco/api/me` | open | `{admin}`, so the SPA knows whether to show the edit controls |
|
||||
|
||||
@@ -12,6 +12,7 @@ import { RouterLink, RouterView } from "vue-router";
|
||||
<nav>
|
||||
<RouterLink to="/" exact-active-class="on">Problems</RouterLink>
|
||||
<RouterLink to="/stats" active-class="on">Stats</RouterLink>
|
||||
<RouterLink to="/cli" active-class="on">CLI</RouterLink>
|
||||
<a href="/">adam-french.co.uk</a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@@ -13,6 +13,7 @@ export default createRouter({
|
||||
{ path: "/", name: "list", component: () => import("@/views/ProblemList.vue") },
|
||||
{ path: "/p/:name", name: "problem", component: () => import("@/views/ProblemPage.vue"), props: true },
|
||||
{ path: "/stats", name: "stats", component: () => import("@/views/StatsPage.vue") },
|
||||
{ path: "/cli", name: "cli", component: () => import("@/views/CliPage.vue") },
|
||||
{ path: "/:pathMatch(.*)*", redirect: "/" },
|
||||
],
|
||||
scrollBehavior: (to, from, saved) => saved || { top: 0 },
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
<script setup>
|
||||
/**
|
||||
* How to use ./usaco, the workspace CLI. A condensed copy of the repo
|
||||
* README's Commands section: the Docker build context is site/, so the README
|
||||
* itself can't be imported. Keep the two in step when the CLI changes.
|
||||
*/
|
||||
|
||||
// Every command that takes a problem name accepts a unique prefix, so the
|
||||
// examples use the full name only where it reads better.
|
||||
const sections = [
|
||||
{
|
||||
title: "Start a problem",
|
||||
rows: [
|
||||
["usaco new <name>", "Create solving/<name>/ with main.cpp from the template and an empty .in file, then open it in $EDITOR."],
|
||||
["usaco new <name> <io>", "Same, when the USACO file name differs from the problem name."],
|
||||
["usaco new <name> --url <link>", "Also save the problem link, for usaco open."],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Build, run and test",
|
||||
rows: [
|
||||
["usaco run <name>", "Compile and run inside the problem dir (so file IO just works), then print the .out file."],
|
||||
["usaco build <name>", "Compile only: g++ -O2 -std=c++17 -Wall -Wextra -DLOCAL."],
|
||||
["usaco test create <name>", "Save a test case: tests/N.in (the current .in, or pasted) and the expected N.out."],
|
||||
["usaco test <name> [N…]", "Build, run every saved case (or just the ones given), diff, and show pass/fail with timings."],
|
||||
["--debug", "On run, build or test (or USACO_DEBUG=1): an ASan/UBSan + _GLIBCXX_DEBUG build, so out-of-bounds and UB crash with a stack trace."],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Finish a problem",
|
||||
rows: [
|
||||
["usaco done <name>", "Move to solved/ and commit “Solve <name>”."],
|
||||
["usaco skip <name>", "Move to skipped/."],
|
||||
["usaco undo <name>", "Bring back to solving/ from solved/ or skipped/."],
|
||||
["usaco sync", "git pull --rebase --autostash && git push: picks up edits made on this site, then publishes your commits."],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Edit and look around",
|
||||
rows: [
|
||||
["usaco e <name>", "Open main.cpp in $EDITOR from inside the problem dir (also vim, edit)."],
|
||||
["usaco list", "All problems by status, oldest-touched first."],
|
||||
["usaco stats", "Counts, plus problems solved in the last 7 and 30 days."],
|
||||
["usaco open <name>", "Open the saved problem link in a browser."],
|
||||
["usaco cat <name>", "Print main.cpp to stdout."],
|
||||
["usaco copy <name>", "Copy main.cpp to the clipboard (wl-copy, xclip/xsel, or OSC52 over SSH)."],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Misc",
|
||||
rows: [
|
||||
["usaco reset <name>", "Fresh main.cpp from the template (the old one goes to main.cpp.bak). Asks first; -y skips. Keeps tests/ and the .in."],
|
||||
["usaco io <name> [new]", "Show the IO name, or rename the .in/.out and rewire STDIO."],
|
||||
["usaco clean", "Delete compiled binaries and .bak files everywhere."],
|
||||
["usaco path <name>", "Print the problem's directory."],
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const session = `usaco new the-lost-cow --url <link>
|
||||
usaco open the-lost-cow # read the problem
|
||||
# paste the sample into solving/the-lost-cow/the-lost-cow.in
|
||||
usaco e the-lost # write main.cpp
|
||||
usaco run the-lost # iterate until the output is right
|
||||
usaco test create the-lost
|
||||
usaco done the-lost # moves it to solved/ and commits
|
||||
usaco sync # publishes it here`;
|
||||
|
||||
const repl = `usaco [none]> s diamond-collector
|
||||
usaco [diamond-collector:solving]> r # run, no name needed
|
||||
usaco [diamond-collector:solving]> t c # create a test case
|
||||
usaco [diamond-collector:solving]> e watermelon # a name switches problem
|
||||
usaco [watermelon:solving]> done
|
||||
usaco [watermelon:solved]> q`;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<section>
|
||||
<h1>The usaco CLI</h1>
|
||||
<p class="muted">
|
||||
Every problem here is written in a workspace managed by <code>./usaco</code>, a small bash script at
|
||||
the repo root. Each problem lives in <code>solving/</code>, <code>solved/</code> or
|
||||
<code>skipped/</code> as a directory with <code>main.cpp</code> and its <code>.in</code>/<code>.out</code>
|
||||
files. Wherever a command takes a problem name, a unique prefix works too:
|
||||
<code>usaco e diam</code> finds <code>diamond-collector</code>.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Setup</h2>
|
||||
<div class="card body">
|
||||
<p>Run it as <code>./usaco</code> from the repo root, or add this to <code>~/.zshrc</code>:</p>
|
||||
<pre><code>source ~/Coding/USACO/usaco.zsh</code></pre>
|
||||
<p>
|
||||
That makes <code>usaco</code> a global command, adds tab completion for commands and problem names, and
|
||||
adds <code>ucd <name></code> to cd into a problem's directory.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>A typical session</h2>
|
||||
<div class="card body">
|
||||
<pre><code>{{ session }}</code></pre>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-for="s in sections" :key="s.title">
|
||||
<h2>{{ s.title }}</h2>
|
||||
<div class="card">
|
||||
<dl>
|
||||
<div v-for="[cmd, what] in s.rows" :key="cmd" class="row">
|
||||
<dt><code>{{ cmd }}</code></dt>
|
||||
<dd>{{ what }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Interactive mode</h2>
|
||||
<div class="card body">
|
||||
<p>
|
||||
<code>usaco i</code> starts a REPL that remembers the current problem, so commands drop the name.
|
||||
It also has <code>push</code>/<code>pop</code> to stash a problem and come back to it,
|
||||
<code>!cmd</code> to run a shell command in the problem dir, and <code>help</code>.
|
||||
</p>
|
||||
<pre><code>{{ repl }}</code></pre>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2>Debug output</h2>
|
||||
<div class="card body">
|
||||
<p>
|
||||
<code>usaco</code> builds define <code>LOCAL</code>, which the template uses to include
|
||||
<code>debugging.h</code> (pretty-printers for vectors, maps and pairs) and enable its
|
||||
<code>DBG(x)</code> macros. The judge doesn't define it, so <code>main.cpp</code> is submittable as-is.
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 28px;
|
||||
}
|
||||
section {
|
||||
min-width: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 2.25rem;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.6rem;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
code {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.875em;
|
||||
}
|
||||
p code {
|
||||
background: var(--color-paper-shade);
|
||||
padding: 1px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 14px 16px;
|
||||
}
|
||||
pre {
|
||||
background: var(--color-paper-tint);
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
overflow-x: auto;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 18rem) minmax(0, 1fr);
|
||||
gap: 4px 16px;
|
||||
padding: 10px 16px;
|
||||
border-bottom: 1px solid var(--color-line-soft);
|
||||
}
|
||||
.row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
dt code {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
dd {
|
||||
color: var(--color-ink-soft);
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.row {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user