|
| 1 | +Add a new project to `dfetch.yaml` and fetch it. |
| 2 | + |
| 3 | +The user may pass a URL or description as `$ARGUMENTS`. If they did not, ask for the URL before proceeding. |
| 4 | + |
| 5 | +## Step 1 — Read the manifest |
| 6 | + |
| 7 | +Read `dfetch.yaml` to understand the existing remotes and project patterns. |
| 8 | + |
| 9 | +## Step 2 — Classify the URL |
| 10 | + |
| 11 | +Determine the VCS type from the URL: |
| 12 | + |
| 13 | +- **archive** — URL ends in `.zip`, `.tar.gz`, `.tar.bz2`, `.tar.xz`, or similar. |
| 14 | +- **svn** — URL contains `svn`, uses `svn+ssh://`, or the user says so. |
| 15 | +- **git** — everything else. |
| 16 | + |
| 17 | +## Step 3 — Gather details |
| 18 | + |
| 19 | +`dfetch add` auto-detects the default branch and guesses a destination, so you only need to ask about things it cannot infer. Use `AskUserQuestion` to collect what you don't yet know: |
| 20 | + |
| 21 | +**For git and SVN:** |
| 22 | + |
| 23 | +Only ask what the user hasn't already told you: |
| 24 | +- **Name** — defaults to the repo name from the URL; confirm or let the user override. |
| 25 | +- **Destination** (`dst`) — where in the repo the files should land; `dfetch add` guesses from existing project paths, but ask if the user has a preference. |
| 26 | +- **Version** — branch, tag, or revision to pin. Leave blank to track the default branch. |
| 27 | +- **Source path** (`src`) — sub-path or glob inside the remote repo (e.g. `lib/` or `*.h`). Leave blank to copy everything. |
| 28 | +- **Ignore patterns** — glob patterns to exclude. Leave blank for none. |
| 29 | + |
| 30 | +**For archives, also ask:** |
| 31 | +- **Source path** (`src`) — sub-directory inside the archive to copy (archives often have a single wrapping top-level directory that dfetch strips automatically). |
| 32 | +- **Ignore patterns** — globs to filter out unwanted files (other font families, binary formats, etc.). |
| 33 | +- **Integrity hash** — whether to verify the download (strongly recommended; you will compute it). |
| 34 | + |
| 35 | +## Step 4 — Add the project |
| 36 | + |
| 37 | +**Git and SVN** — use the CLI, which appends the entry to `dfetch.yaml` and records the resolved remote: |
| 38 | + |
| 39 | +```bash |
| 40 | +dfetch add --name <name> --dst <dst> [--src <src>] [--version <version>] \ |
| 41 | + [--ignore <p1> <p2> ...] <url> |
| 42 | +``` |
| 43 | + |
| 44 | +Omit flags for fields the user left blank; `dfetch add` will fill in sensible defaults. |
| 45 | + |
| 46 | +**Archives** — edit `dfetch.yaml` directly with the Edit tool. The CLI does not support `vcs: archive`, `integrity:`, or archive-specific `src` paths. Follow the style of existing archive entries: |
| 47 | + |
| 48 | +```yaml |
| 49 | +- name: <name> |
| 50 | + remote: <remote> # use an existing remote if its url-base is a prefix of the URL; omit otherwise |
| 51 | + vcs: archive |
| 52 | + src: <path-in-archive> # omit if copying from the archive root |
| 53 | + dst: <dst> |
| 54 | + repo-path: <url-or-path> |
| 55 | + ignore: |
| 56 | + - <pattern> |
| 57 | + integrity: |
| 58 | + hash: sha256:<hash> |
| 59 | +``` |
| 60 | +
|
| 61 | +Compute the hash before writing the entry: |
| 62 | +
|
| 63 | +```bash |
| 64 | +curl -sL <url> | sha256sum |
| 65 | +``` |
| 66 | + |
| 67 | +When reusing an existing remote, `repo-path` is the URL suffix after the remote's `url-base`. When no remote matches, omit `remote:` and use the full URL as `repo-path`. |
| 68 | + |
| 69 | +## Step 5 — Fetch and verify |
| 70 | + |
| 71 | +Run `dfetch update <name>`. If it fails: |
| 72 | + |
| 73 | +| Error | Fix | |
| 74 | +|---|---| |
| 75 | +| `src … not found in archive` | Inspect the archive with `unzip -l <file>` or `tar -tf <file>`. If the archive has a single top-level wrapper directory, dfetch strips it — adjust `src` accordingly. | |
| 76 | +| Integrity mismatch | Recompute the hash and update the `integrity` field. | |
| 77 | +| Remote not found | Check that `remote:` matches a name in the `remotes:` list. | |
| 78 | +| Branch/tag not found | Run `dfetch add -i <url>` in a terminal to browse available versions interactively, then copy the chosen value back into the manifest. | |
| 79 | + |
| 80 | +## Step 6 — Confirm |
| 81 | + |
| 82 | +Show the user the new entry that was added to `dfetch.yaml` and list the files that were fetched to `dst`. |
0 commit comments