From 0c4c560302242d9f0418255747319e415f10003b Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Fri, 23 May 2025 17:39:48 +0200 Subject: [PATCH 1/3] fix spaces/... url --- packages/hub/cli.ts | 82 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/packages/hub/cli.ts b/packages/hub/cli.ts index be861ace5a..471f7cd8ca 100644 --- a/packages/hub/cli.ts +++ b/packages/hub/cli.ts @@ -2,7 +2,7 @@ import { parseArgs } from "node:util"; import { typedEntries } from "./src/utils/typedEntries"; -import { createBranch, createRepo, deleteBranch, repoExists, uploadFilesWithProgress } from "./src"; +import { createBranch, createRepo, deleteBranch, deleteRepo, repoExists, uploadFilesWithProgress } from "./src"; import { pathToFileURL } from "node:url"; import { stat } from "node:fs/promises"; import { basename, join } from "node:path"; @@ -78,7 +78,6 @@ const commands = { { name: "repo-type" as const, enum: ["dataset", "model", "space"], - default: "model", description: "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", }, @@ -126,7 +125,6 @@ const commands = { { name: "repo-type" as const, enum: ["dataset", "model", "space"], - default: "model", description: "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", }, @@ -173,7 +171,6 @@ const commands = { { name: "repo-type" as const, enum: ["dataset", "model", "space"], - default: "model", description: "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", }, @@ -187,6 +184,35 @@ const commands = { }, }, } satisfies CommandGroup, + repo: { + description: "Manage repositories on the Hub", + subcommands: { + delete: { + description: "Delete a repository from the Hub", + args: [ + { + name: "repo-name" as const, + description: + "The full ID of the repo to delete (e.g., 'username/my-model', 'datasets/username/my-data', or 'spaces/username/my-space')", + positional: true, + required: true, + }, + { + name: "repo-type" as const, + enum: ["dataset", "model", "space"], + description: + "The type of repo. If the repo-name is prefixed (e.g. 'datasets/my-dataset'), the type is inferred. This option can be used to override or specify the type if the name is not prefixed.", + }, + { + name: "token" as const, + description: + "The access token to use for authentication. If not provided, the HF_TOKEN environment variable will be used.", + default: process.env.HF_TOKEN, + }, + ] as const, + }, + }, + } satisfies CommandGroup, version: { description: "Print the version of the CLI", args: [] as const, @@ -389,6 +415,54 @@ async function run() { } break; } + case "repo": { + const repoCommandGroup = commands.repo; + const currentSubCommandName = subCommandName as keyof typeof repoCommandGroup.subcommands | undefined; + + if (cliArgs[0] === "--help" || cliArgs[0] === "-h") { + if (currentSubCommandName && repoCommandGroup.subcommands[currentSubCommandName]) { + console.log(detailedUsageForSubcommand("repo", currentSubCommandName)); + } else { + console.log(listSubcommands("repo", repoCommandGroup)); + } + break; + } + + if (!currentSubCommandName || !repoCommandGroup.subcommands[currentSubCommandName]) { + console.error(`Error: Missing or invalid subcommand for 'repo'.`); + console.log(listSubcommands("repo", repoCommandGroup)); + process.exitCode = 1; + break; + } + + const subCmdDef = repoCommandGroup.subcommands[currentSubCommandName]; + + switch (currentSubCommandName) { + case "delete": { + const parsedArgs = advParseArgs(cliArgs, subCmdDef.args, `repo ${currentSubCommandName}`); + const { repoName, repoType, token } = parsedArgs; + + const repoDesignation: Parameters[0]["repo"] = repoType + ? { type: repoType as "model" | "dataset" | "space", name: repoName } + : repoName; + + await deleteRepo({ + repo: repoDesignation, + accessToken: token, + hubUrl: process.env.HF_ENDPOINT ?? HUB_URL, + }); + console.log(`Repository '${repoName}' deleted successfully.`); + break; + } + default: + // This case should ideally be caught by the check above + console.error(`Error: Unknown subcommand '${currentSubCommandName}' for 'repo'.`); + console.log(listSubcommands("repo", repoCommandGroup)); + process.exitCode = 1; + break; + } + break; + } case "version": { if (cliArgs[0] === "--help" || cliArgs[0] === "-h") { console.log(detailedUsageForCommand("version")); From 6ddba281819e7ce6959461a617a05ee19823074d Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Fri, 23 May 2025 17:44:09 +0200 Subject: [PATCH 2/3] nit doc --- packages/hub/cli.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/hub/cli.ts b/packages/hub/cli.ts index 471f7cd8ca..018f3eac86 100644 --- a/packages/hub/cli.ts +++ b/packages/hub/cli.ts @@ -126,7 +126,7 @@ const commands = { name: "repo-type" as const, enum: ["dataset", "model", "space"], description: - "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", + "The type of 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", }, { name: "revision" as const, @@ -193,7 +193,7 @@ const commands = { { name: "repo-name" as const, description: - "The full ID of the repo to delete (e.g., 'username/my-model', 'datasets/username/my-data', or 'spaces/username/my-space')", + "The name of the repo to delete. You can also prefix the repo name with the type, e.g. datasets/username/repo-name", positional: true, required: true, }, @@ -201,7 +201,7 @@ const commands = { name: "repo-type" as const, enum: ["dataset", "model", "space"], description: - "The type of repo. If the repo-name is prefixed (e.g. 'datasets/my-dataset'), the type is inferred. This option can be used to override or specify the type if the name is not prefixed.", + "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", }, { name: "token" as const, From 982956b9b5a80262ecb533cc2991ccbf41dddccb Mon Sep 17 00:00:00 2001 From: "Eliott C." Date: Sun, 25 May 2025 01:25:00 +0200 Subject: [PATCH 3/3] Update packages/hub/cli.ts Co-authored-by: Pedro Cuenca --- packages/hub/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hub/cli.ts b/packages/hub/cli.ts index 018f3eac86..dda64c4ada 100644 --- a/packages/hub/cli.ts +++ b/packages/hub/cli.ts @@ -126,7 +126,7 @@ const commands = { name: "repo-type" as const, enum: ["dataset", "model", "space"], description: - "The type of 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", + "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", }, { name: "revision" as const,