A Source link in the header, and on the CLI page links to the script, lib/cmd, usaco.zsh, the README, the template and debugging.h, plus the clone URL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
216 lines
7.5 KiB
Vue
216 lines
7.5 KiB
Vue
<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.
|
|
*/
|
|
|
|
// The repo on the site's Gitea, behind the same nginx, so a root-relative
|
|
// link works.
|
|
const repo = "/gitea/adamf/usaco";
|
|
const src = (path) => `${repo}/src/branch/main/${path}`;
|
|
|
|
// 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 <a :href="src('usaco')"><code>./usaco</code></a>, a small bash script at
|
|
the root of <a :href="repo">the repo on Gitea</a> (the commands themselves are in
|
|
<a :href="src('lib/cmd')"><code>lib/cmd/</code></a>). 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>Clone the repo and run <code>./usaco</code> from its root:</p>
|
|
<pre><code>git clone https://www.adam-french.co.uk{{ repo }}.git</code></pre>
|
|
<p>Or add this to <code>~/.zshrc</code>:</p>
|
|
<pre><code>source ~/Coding/USACO/<a :href="src('usaco.zsh')">usaco.zsh</a></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. The full reference is the
|
|
<a :href="src('README.md')">README</a>.
|
|
</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 <a :href="src('template.cpp')">template</a> uses to include
|
|
<a :href="src('debugging.h')"><code>debugging.h</code></a> (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>
|