How qryxip/cargo-compete works
Project type and purpose
• cargo-compete is a Rust-based CLI application that augments Cargo with subcommands to streamline competitive programming workflows (init, login, new, add, test, submit, etc.).
• It acts as an orchestrator: reading configs and templates, invoking web APIs (AtCoder, Codeforces, yukicoder, Dropbox), manipulating files (Cargo.toml, testcases/*.yml), and launching external processes (cargo build/test, oj-api, shell commands).
File structure
Top level:
• .github, workflows, CI config
• resources/ – static templates and toml snippets
• src/
– commands/ (each subcommand as a module)
– web/ (URL builders, HTTP clients for downloading testcases)
– oj_api.rs (wrapper for external online-judge-tools API)
– fs.rs (file‐system helpers)
– config.rs (parsing compete.toml)
– project.rs (Cargo-project abstractions)
– process.rs (running subprocesses)
– shell.rs (invoking shell commands)
– testing.rs (injecting and running tests)
– main.rs (CLI dispatch), lib.rs (library entry)
• tests/ – integration and snapshot tests
README for additional insights
• Core features: login, register, scaffold contest packages, retrieve sample/system test cases, run tests, submit, watch.
• Uses Serde/Liquid for templating.
• Stores cookies/tokens in user data directory.
• Supports extensibility via compete.toml (templates, commands, hooks).
Main components
a. CLI Front-End
– User’s terminal invokes cargo compete <command>.
– Clap (or similar) in main.rs routes to subcommand modules in src/commands.
b. Configuration Layer
– config.rs reads compete.toml and Cargo.toml metadata.
– resources/ provide default templates.
c. Command Modules
– commands/* implement business logic per subcommand: init, new, add, test, submit, etc.
– They call into:
• fs.rs for scaffolding files and directories
• project.rs for manipulating Cargo projects
• process.rs + shell.rs to run Cargo or custom commands
• testing.rs to wire up YAML testcases into Cargo test harness
d. API Client Layer
– web/ modules and oj_api.rs wrap HTTP calls to AtCoder, Codeforces, yukicoder, Dropbox, or fallback to online-judge-tools CLI.
– Manage authentication (cookies.jsonl, tokens/*.json) under data_local_dir.
e. Persistence/File-System
– Generated files: compete.toml, .cargo/config.toml, template-Cargo.lock.toml
– Per-problem/testcases/*.yml
– Cache directories: system-test-cases under cache_dir.
f. External Services
– HTTP endpoints of competitive-programming sites
– Dropbox API for system test cases
– online-judge-tools executable as fallback
g. Process Execution
– cargo build/test commands, user-configured submit pipelines (cargo-equip, exec-payload).
Relationships and data flows
• User → CLI Front-End → Configuration Layer
• Subcommand Module ↔ File-System (create/read/write project files & testcases)
• Subcommand Module ↔ API Client Layer → External Web Services
• Subcommand Module → Process Execution → local Cargo or shell commands
• Test and submit commands read YAML suites and drive Cargo/test or HTTP POST
Architectural patterns and principles
• Modular CLI subcommands each encapsulate one responsibility.
• Layered architecture: presentation (CLI) → application (commands) → infrastructure (fs, network, process).
• Dependency injection of config/paths into command handlers.
• Plugin-style templates via Liquid.
• Clean separation between synchronous filesystem work and asynchronous HTTP (if using async runtimes).
Technologies and frameworks
• Rust toolchain: Cargo, clap or structopt (CLI parsing), serde (config & YAML), reqwest or surf (HTTP), liquid (templating), directories (dirs-next), subprocess (std::process).
• External: online-judge-tools, Dropbox API, site-specific HTTP endpoints.