oj-submit 0.1.0

A fast, simple CLI for submitting solutions to the UVA Online Judge (onlinejudge.org)
# oj-submit

A fast, simple CLI tool for submitting solutions to [UVA Online Judge](https://onlinejudge.org).

`oj-submit` handles the entire submission workflow — from login to verdict — right in your terminal. Write your solution, run one command, and watch the judge evaluate it in real time.

## Features

- **Secure credential storage** — credentials saved at `~/.config/oj-submit/` with owner-only file permissions
- **Auto-detect language** — automatically determines the programming language from your file extension
- **Auto-extract problem ID** — pulls the problem number from your filename (`100.cpp` → problem 100)
- **Real-time verdict polling** — polls the judge with a live progress indicator until your submission is evaluated
- **Colored terminal output** — verdicts, errors, and status messages are color-coded for quick scanning
- **Rate limiting** — respectful polling intervals to avoid hammering the server

## Installation

### Prerequisites

- [Rust]https://www.rust-lang.org/tools/install 1.85+ (edition 2024)

### From crates.io

```bash
cargo install oj-submit
```

### From source

```bash
git clone https://github.com/rohaquinlop/one-line-judge-submitter.git
cd one-line-judge-submitter
cargo install --path .
```

### Or build locally

```bash
cargo build --release
# Binary will be at ./target/release/oj-submit
```

## Quick Start

**Step 1:** Log in with your UVA Online Judge credentials:

```bash
oj-submit login
```

**Step 2:** Submit a solution — the problem ID and language are detected automatically:

```bash
oj-submit 100.cpp
```

**Step 3:** Watch the verdict come in:

```
→ Logging in as your_username...
✓ Submitted! Run ID: 31184153 (initial verdict: In judge queue)
⏳ Polling for verdict (Ctrl+C to cancel)...

Run ID:   31184153
Problem:  100 (The 3n + 1 problem)
Verdict:  Accepted
Language: C++11
Runtime:  0.310
Date:     2026-06-19 16:45:57
```

## Usage

### Login

Store your UVA credentials:

```bash
oj-submit login
```

You will be prompted for your username and password. Credentials are saved to `~/.config/oj-submit/credentials.json` with `600` permissions (owner read/write only).

### Logout

Remove stored credentials:

```bash
oj-submit logout
```

### Submit

Submit a source file to the UVA Online Judge:

```bash
oj-submit <FILE> [OPTIONS]
```

| Option | Description |
|---|---|
| `--problem <ID>` | Override the auto-detected problem ID |
| `--verbose` | Print detailed HTTP and parsing debug info |
| `--no-wait` | Submit without waiting for the verdict |

**Examples:**

```bash
# Auto-detect problem ID (100) and language (C++11) from filename
oj-submit 100.cpp

# Override the problem ID
oj-submit solution.cpp --problem 1234

# Submit and exit immediately without polling for verdict
oj-submit main.py --no-wait

# Debug mode — see HTTP requests, form fields, and parsing steps
oj-submit 100.cpp --verbose
```

### Status

View your recent submissions (via uHunt API):

```bash
oj-submit status [--verbose]
```

## Supported Languages

| Extension | Language | Code |
|---|---|---|
| `.c` | ANSI C | 1 |
| `.java` | Java | 2 |
| `.cpp`, `.cc`, `.cxx`, `.C` | C++11 | 5 |
| `.pas` | Pascal | 4 |
| `.py`, `.py3` | Python 3 | 6 |

The language is auto-detected from the file extension. There is no need to specify it manually.

## Problem ID Detection

`oj-submit` extracts the problem number from your filename by finding the first contiguous group of digits in the file stem (name without extension).

| Filename | Detected Problem ID |
|---|---|
| `100.cpp` | 100 |
| `uva_1234.py` | 1234 |
| `UVa100.java` | 100 |
| `problem7.cpp` | 7 |
| `500.py` | 500 |
| `solution.cpp` | *(none — you must use `--problem`)* |

If the filename contains no digits, you must specify the problem ID explicitly:

```bash
oj-submit solution.cpp --problem 100
```

## Verdicts

After submission, `oj-submit` polls the status page until a final verdict is returned:

| Verdict | Description |
|---|---|
|**Accepted** | Your solution passed all test cases |
|**Wrong Answer** | Output did not match the expected result |
| ⏱️ **Time Limit Exceeded** | Solution exceeded the time limit |
| 💾 **Memory Limit Exceeded** | Solution used too much memory |
| 💥 **Runtime Error** | Solution crashed during execution |
| ⚠️ **Compile Error** | Code did not compile |
| 🚫 **Output Limit Exceeded** | Output was too large |
| 🔍 **Restricted Function** | Used a forbidden function or system call |
|**In judge queue** | Waiting to be judged *(intermediate status)* |

## Security

- **Credentials are stored in `~/.config/oj-submit/credentials.json`** with owner-only file permissions (600). The file is plain JSON — you can inspect or delete it at any time.
- **Session cookies are not persisted** — each invocation creates a fresh HTTP session. Logging out removes the credentials file.
- **No telemetry or tracking** — the tool makes only the requests necessary for login, submission, and verdict polling.

## Troubleshooting

| Problem | Solution |
|---|---|
| `No credentials found. Run 'oj-submit login' first.` | You haven't logged in yet. Run `oj-submit login`. |
| `Login failed: Incorrect username or password` | Double-check your UVA username and password. Make sure Caps Lock is off. |
| `Polling timed out after 120 seconds` | The judge may be under heavy load. Your submission is still queued — try `oj-submit status` later. |
| `Unsupported file extension '.xyz'` | Your file extension isn't recognized. See [Supported Languages]#supported-languages. Use `--problem` if needed. |
| Verdict seems wrong or stale | Use `--verbose` to inspect the raw HTTP responses and parsed data. |

For any other issue, run with `--verbose` to get detailed debug output:

```bash
oj-submit 100.cpp --verbose
```

## License

[MIT](LICENSE)