Skip to content

Commit 0be6a40

Browse files
committed
add delete-branch and version commands
1 parent 8f96728 commit 0be6a40

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

packages/hub/cli.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import { parseArgs } from "node:util";
44
import { typedEntries } from "./src/utils/typedEntries";
5-
import { createBranch, uploadFilesWithProgress } from "./src";
5+
import { createBranch, deleteBranch, uploadFilesWithProgress } from "./src";
66
import { pathToFileURL } from "node:url";
77
import { stat } from "node:fs/promises";
88
import { basename, join } from "node:path";
99
import { HUB_URL } from "./src/consts";
10+
import { version } from "./package.json";
1011

1112
// Didn't find the import from "node:util", so duplicated it here
1213
type OptionToken =
@@ -80,6 +81,11 @@ const commands = {
8081
name: "commit-message" as const,
8182
description: "The commit message to use. Defaults to 'Add [x] files'",
8283
},
84+
{
85+
name: "private" as const,
86+
description: "If creating a new repo, make it private",
87+
boolean: true,
88+
},
8389
{
8490
name: "token" as const,
8591
description:
@@ -135,6 +141,40 @@ const commands = {
135141
},
136142
],
137143
} 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+
},
138178
} satisfies Record<
139179
string,
140180
{
@@ -225,6 +265,30 @@ async function run() {
225265
});
226266
break;
227267
}
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+
}
228292
default:
229293
throw new Error("Command not found: " + command);
230294
}

packages/hub/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"moduleResolution": "node",
77
"target": "ES2022",
88
"forceConsistentCasingInFileNames": true,
9+
"resolveJsonModule": true,
910
"strict": true,
1011
"noImplicitAny": true,
1112
"strictNullChecks": true,

0 commit comments

Comments
 (0)