|
2 | 2 |
|
3 | 3 | import { parseArgs } from "node:util"; |
4 | 4 | import { typedEntries } from "./src/utils/typedEntries"; |
5 | | -import { createBranch, uploadFilesWithProgress } from "./src"; |
| 5 | +import { createBranch, deleteBranch, uploadFilesWithProgress } from "./src"; |
6 | 6 | import { pathToFileURL } from "node:url"; |
7 | 7 | import { stat } from "node:fs/promises"; |
8 | 8 | import { basename, join } from "node:path"; |
9 | 9 | import { HUB_URL } from "./src/consts"; |
| 10 | +import { version } from "./package.json"; |
10 | 11 |
|
11 | 12 | // Didn't find the import from "node:util", so duplicated it here |
12 | 13 | type OptionToken = |
@@ -80,6 +81,11 @@ const commands = { |
80 | 81 | name: "commit-message" as const, |
81 | 82 | description: "The commit message to use. Defaults to 'Add [x] files'", |
82 | 83 | }, |
| 84 | + { |
| 85 | + name: "private" as const, |
| 86 | + description: "If creating a new repo, make it private", |
| 87 | + boolean: true, |
| 88 | + }, |
83 | 89 | { |
84 | 90 | name: "token" as const, |
85 | 91 | description: |
@@ -135,6 +141,40 @@ const commands = { |
135 | 141 | }, |
136 | 142 | ], |
137 | 143 | } as const, |
| 144 | + "delete-branch": { |
| 145 | + description: "Delete a branch in a repo", |
| 146 | + args: [ |
| 147 | + { |
| 148 | + name: "repo-name" as const, |
| 149 | + description: "The name of the repo to delete the branch from", |
| 150 | + positional: true, |
| 151 | + required: true, |
| 152 | + }, |
| 153 | + { |
| 154 | + name: "branch" as const, |
| 155 | + description: "The name of the branch to delete", |
| 156 | + positional: true, |
| 157 | + required: true, |
| 158 | + }, |
| 159 | + { |
| 160 | + name: "repo-type" as const, |
| 161 | + enum: ["dataset", "model", "space"], |
| 162 | + default: "model", |
| 163 | + description: |
| 164 | + "The type of repo to delete the branch from. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name", |
| 165 | + }, |
| 166 | + { |
| 167 | + name: "token" as const, |
| 168 | + description: |
| 169 | + "The access token to use for authentication. If not provided, the HF_TOKEN environment variable will be used.", |
| 170 | + default: process.env.HF_TOKEN, |
| 171 | + }, |
| 172 | + ], |
| 173 | + }, |
| 174 | + version: { |
| 175 | + description: "Print the version of the CLI", |
| 176 | + args: [], |
| 177 | + }, |
138 | 178 | } satisfies Record< |
139 | 179 | string, |
140 | 180 | { |
@@ -225,6 +265,30 @@ async function run() { |
225 | 265 | }); |
226 | 266 | break; |
227 | 267 | } |
| 268 | + case "delete-branch": { |
| 269 | + if (args[0] === "--help" || args[0] === "-h") { |
| 270 | + console.log(detailedUsage("delete-branch")); |
| 271 | + break; |
| 272 | + } |
| 273 | + const parsedArgs = advParseArgs(args, "delete-branch"); |
| 274 | + const { repoName, branch, repoType, token } = parsedArgs; |
| 275 | + |
| 276 | + await deleteBranch({ |
| 277 | + repo: repoType ? { type: repoType as "model" | "dataset" | "space", name: repoName } : repoName, |
| 278 | + branch, |
| 279 | + accessToken: token, |
| 280 | + hubUrl: process.env.HF_ENDPOINT ?? HUB_URL, |
| 281 | + }); |
| 282 | + break; |
| 283 | + } |
| 284 | + case "version": { |
| 285 | + if (args[0] === "--help" || args[0] === "-h") { |
| 286 | + console.log(detailedUsage("version")); |
| 287 | + break; |
| 288 | + } |
| 289 | + console.log(`hfjs version: ${version}`); |
| 290 | + break; |
| 291 | + } |
228 | 292 | default: |
229 | 293 | throw new Error("Command not found: " + command); |
230 | 294 | } |
|
0 commit comments