Content-Length: 496518 | pFad | http://github.com/huggingface/huggingface.js/commit/80e27d6bc2411b5d197a1ca43ed13d960fb3907f

2E CLI: Delete repo (#1486) · huggingface/huggingface.js@80e27d6 · GitHub
Skip to content

Commit 80e27d6

Browse files
coyotte508pcuenca
andauthored
CLI: Delete repo (#1486)
Easier to do it that way than through the hub's UI 😅 --------- Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
1 parent b20d7c5 commit 80e27d6

File tree

1 file changed

+79
-5
lines changed

1 file changed

+79
-5
lines changed

packages/hub/cli.ts

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { parseArgs } from "node:util";
44
import { typedEntries } from "./src/utils/typedEntries";
5-
import { createBranch, createRepo, deleteBranch, repoExists, uploadFilesWithProgress } from "./src";
5+
import { createBranch, createRepo, deleteBranch, deleteRepo, repoExists, uploadFilesWithProgress } from "./src";
66
import { pathToFileURL } from "node:url";
77
import { stat } from "node:fs/promises";
88
import { basename, join } from "node:path";
@@ -78,7 +78,6 @@ const commands = {
7878
{
7979
name: "repo-type" as const,
8080
enum: ["dataset", "model", "space"],
81-
default: "model",
8281
description:
8382
"The type of repo to upload to. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
8483
},
@@ -126,9 +125,8 @@ const commands = {
126125
{
127126
name: "repo-type" as const,
128127
enum: ["dataset", "model", "space"],
129-
default: "model",
130128
description:
131-
"The type of repo to create. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
129+
"The type of the repo to create the branch into. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
132130
},
133131
{
134132
name: "revision" as const,
@@ -173,7 +171,6 @@ const commands = {
173171
{
174172
name: "repo-type" as const,
175173
enum: ["dataset", "model", "space"],
176-
default: "model",
177174
description:
178175
"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",
179176
},
@@ -187,6 +184,35 @@ const commands = {
187184
},
188185
},
189186
} satisfies CommandGroup,
187+
repo: {
188+
description: "Manage repositories on the Hub",
189+
subcommands: {
190+
delete: {
191+
description: "Delete a repository from the Hub",
192+
args: [
193+
{
194+
name: "repo-name" as const,
195+
description:
196+
"The name of the repo to delete. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
197+
positional: true,
198+
required: true,
199+
},
200+
{
201+
name: "repo-type" as const,
202+
enum: ["dataset", "model", "space"],
203+
description:
204+
"The type of the repo to delete. Defaults to model. You can also prefix the repo name with the type, e.g. datasets/username/repo-name",
205+
},
206+
{
207+
name: "token" as const,
208+
description:
209+
"The access token to use for authentication. If not provided, the HF_TOKEN environment variable will be used.",
210+
default: process.env.HF_TOKEN,
211+
},
212+
] as const,
213+
},
214+
},
215+
} satisfies CommandGroup,
190216
version: {
191217
description: "Print the version of the CLI",
192218
args: [] as const,
@@ -389,6 +415,54 @@ async function run() {
389415
}
390416
break;
391417
}
418+
case "repo": {
419+
const repoCommandGroup = commands.repo;
420+
const currentSubCommandName = subCommandName as keyof typeof repoCommandGroup.subcommands | undefined;
421+
422+
if (cliArgs[0] === "--help" || cliArgs[0] === "-h") {
423+
if (currentSubCommandName && repoCommandGroup.subcommands[currentSubCommandName]) {
424+
console.log(detailedUsageForSubcommand("repo", currentSubCommandName));
425+
} else {
426+
console.log(listSubcommands("repo", repoCommandGroup));
427+
}
428+
break;
429+
}
430+
431+
if (!currentSubCommandName || !repoCommandGroup.subcommands[currentSubCommandName]) {
432+
console.error(`Error: Missing or invalid subcommand for 'repo'.`);
433+
console.log(listSubcommands("repo", repoCommandGroup));
434+
process.exitCode = 1;
435+
break;
436+
}
437+
438+
const subCmdDef = repoCommandGroup.subcommands[currentSubCommandName];
439+
440+
switch (currentSubCommandName) {
441+
case "delete": {
442+
const parsedArgs = advParseArgs(cliArgs, subCmdDef.args, `repo ${currentSubCommandName}`);
443+
const { repoName, repoType, token } = parsedArgs;
444+
445+
const repoDesignation: Parameters<typeof deleteRepo>[0]["repo"] = repoType
446+
? { type: repoType as "model" | "dataset" | "space", name: repoName }
447+
: repoName;
448+
449+
await deleteRepo({
450+
repo: repoDesignation,
451+
accessToken: token,
452+
hubUrl: process.env.HF_ENDPOINT ?? HUB_URL,
453+
});
454+
console.log(`Repository '${repoName}' deleted successfully.`);
455+
break;
456+
}
457+
default:
458+
// This case should ideally be caught by the check above
459+
console.error(`Error: Unknown subcommand '${currentSubCommandName}' for 'repo'.`);
460+
console.log(listSubcommands("repo", repoCommandGroup));
461+
process.exitCode = 1;
462+
break;
463+
}
464+
break;
465+
}
392466
case "version": {
393467
if (cliArgs[0] === "--help" || cliArgs[0] === "-h") {
394468
console.log(detailedUsageForCommand("version"));

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/huggingface/huggingface.js/commit/80e27d6bc2411b5d197a1ca43ed13d960fb3907f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy