# CLI Reference

## Global Options

```
axm-bib --help       Show help
axm-bib --version    Show version
```

## `search` — Search Papers

```
axm-bib search [OPTIONS] QUERY
```

| Option | Short | Type | Default | Description |
|---|---|---|---|---|
| `QUERY` | | string | *required* | Search query (title, keywords) |
| `--limit` | `-n` | int | 5 | Max results (1–100, clamped) |
| `--abstract/--no-abstract` | | bool | `True` | Show abstracts |
| `--abstract-len` | | int | 0 | Truncate to N chars (0 = full) |

**Validation rules:**

- `limit` < 1 → error
- `limit` > 100 → clamped to 100
- Empty query → error

**Example:**

```bash
axm-bib search "loop invariants" -n 10 --abstract-len 150
```

---

## `doi` — Resolve DOI to BibTeX

```
axm-bib doi DOI
```

| Option | Type | Description |
|---|---|---|
| `DOI` | string | Digital Object Identifier |

**Example:**

```bash
axm-bib doi 10.1145/363235.363259
```

---

## `pdf` — Download, Extract & Organize Paper

```
axm-bib pdf [OPTIONS] DOI
```

| Option | Short | Type | Default | Description |
|---|---|---|---|---|
| `DOI` | | string | *required* | DOI to download |
| `--output-dir` | `-o` | path | `~/axm/papers/` | Output directory |

Downloads the open-access PDF, extracts Markdown + figures, and writes `paper.bib`.

**Output structure:**

```
~/axm/papers/{key}/
├── {key}.pdf       # downloaded PDF
├── paper.bib       # BibTeX entry
├── content.md      # extracted Markdown
└── figures/
    ├── fig_001.png
    └── ...
```

**arXiv fallback:** If Unpaywall has no URL but the DOI is an arXiv paper (`10.48550/arXiv.*`), downloads directly from `arxiv.org/pdf/`.

**Example:**

```bash
axm-bib pdf 10.48550/arXiv.1706.03762
```

```
Downloaded: ~/axm/papers/vaswani2017attention
  PDF: vaswani2017attention.pdf (1,234,567 bytes)
  BibTeX: paper.bib
  Markdown: content.md (45,123 chars, 12 pages)
  Figures: 8
```

---

## `extract` — Extract Local PDF

```
axm-bib extract [OPTIONS] PDF_PATH
```

| Option | Short | Type | Default | Description |
|---|---|---|---|---|
| `PDF_PATH` | | path | *required* | Path to PDF file |
| `--output-dir` | `-o` | path | auto | Output directory |
| `--figures/--no-figures` | | bool | `True` | Extract figures as PNG |

Extracts Markdown + figures from a local PDF without downloading anything.

**Example:**

```bash
axm-bib extract paper.pdf -o ~/extracted/
```

```
Extracted: ~/extracted/
  Markdown: content.md (32,000 chars)
  Pages: 8
  Figures: 3
```
