|
| 1 | +# CLI 設計規範:textutil 向下相容 |
| 2 | + |
| 3 | +## 原則 |
| 4 | + |
| 5 | +macdoc CLI 的轉換指令必須與 macOS 內建 `textutil` 的語法模式相容。 |
| 6 | +使用者如果會用 `textutil`,應該能直覺地使用 `macdoc`。 |
| 7 | + |
| 8 | +## textutil 參考語法 |
| 9 | + |
| 10 | +```bash |
| 11 | +textutil -convert fmt [options] file... |
| 12 | +textutil -info file... |
| 13 | +textutil -cat fmt file... |
| 14 | +``` |
| 15 | + |
| 16 | +核心特徵: |
| 17 | +- **動作在前**(`-convert`, `-info`) |
| 18 | +- **格式是動作的參數**(`-convert html`) |
| 19 | +- **檔案放最後** |
| 20 | +- **input format 從副檔名自動偵測**(除非用 `-format` 覆蓋) |
| 21 | +- **output 預設同目錄換副檔名**(除非用 `-output` 指定) |
| 22 | + |
| 23 | +## macdoc 對應語法 |
| 24 | + |
| 25 | +```bash |
| 26 | +# 轉換(對應 textutil -convert) |
| 27 | +macdoc convert --to md file.docx |
| 28 | +macdoc convert --to html file.md |
| 29 | +macdoc convert --to html --style apa file.bib |
| 30 | +macdoc convert --to tokens file.md |
| 31 | +macdoc convert --to tokens --model gpt-4o file.md |
| 32 | + |
| 33 | +# 資訊(對應 textutil -info) |
| 34 | +macdoc info file.docx |
| 35 | + |
| 36 | +# 輸出控制(對應 textutil -output / -stdout) |
| 37 | +macdoc convert --to md --output result.md file.docx |
| 38 | +macdoc convert --to md --stdout file.docx |
| 39 | +``` |
| 40 | + |
| 41 | +## 設計規則 |
| 42 | + |
| 43 | +1. **檔案永遠放最後** — 跟 textutil、Unix 慣例一致 |
| 44 | +2. **input format 自動偵測** — 從副檔名推斷,不需要使用者指定 |
| 45 | +3. **用 `--` long flags** — 遵循 swift-argument-parser 慣例(`--to`, `--output`),不用 textutil 的單 dash(`-convert`) |
| 46 | +4. **轉換統一用 `convert` subcommand** — 所有格式轉換走同一個入口 |
| 47 | +5. **非轉換功能用獨立 subcommand** — `pdf init/status/...`、`config ai detect/...` 維持現狀 |
| 48 | +6. **`--to` 的值是 target format 短名** — `md`, `html`, `json`, `latex`, `tokens` |
| 49 | + |
| 50 | +## Format 短名對照 |
| 51 | + |
| 52 | +| --to 值 | 全名 | 對應 package | |
| 53 | +|---------|------|-------------| |
| 54 | +| `md` | Markdown | `word-to-md-swift`, `html-to-md-swift` | |
| 55 | +| `html` | HTML | `md-to-html-swift`, `srt-to-html-swift`, `bib-apa-to-html-swift` | |
| 56 | +| `json` | JSON | `bib-apa-to-json-swift` | |
| 57 | +| `latex` | LaTeX | `pdf-to-latex-swift` | |
| 58 | +| `tokens` | Token count | `token-counter-swift` | |
| 59 | + |
| 60 | +## 遷移 |
| 61 | + |
| 62 | +現有的 `macdoc word to-md`、`macdoc html to-md` 等指令在遷移期間保留為 alias, |
| 63 | +新功能一律用 `macdoc convert --to` 格式。最終目標是統一到 `convert` 入口。 |
0 commit comments