Skip to content

Commit f831b3c

Browse files
committed
add hidden hub-url CLI param
1 parent f735cfa commit f831b3c

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

packages/hub/cli.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { parseArgs } from "node:util";
44
import { typedEntries } from "./src/utils/typedEntries";
55
import { createBranch, uploadFilesWithProgress } from "./src";
66
import { pathToFileURL } from "node:url";
7+
import { HUB_URL } from "./src/consts";
78

89
// Didn't find the import from "node:util", so duplicated it here
910
type OptionToken =
@@ -83,6 +84,13 @@ const commands = {
8384
"The access token to use for authentication. If not provided, the HF_TOKEN environment variable will be used.",
8485
default: process.env.HF_TOKEN,
8586
},
87+
{
88+
name: "hub-url" as const,
89+
description:
90+
"The URL of the Hub to upload to. Defaults to https://huggingface.co. Use this to upload to a private Hub.",
91+
hidden: true,
92+
default: HUB_URL,
93+
},
8694
],
8795
},
8896
} satisfies Record<
@@ -97,6 +105,7 @@ const commands = {
97105
required?: boolean;
98106
boolean?: boolean;
99107
enum?: Array<string>;
108+
hidden?: boolean;
100109
default?: string | (() => string);
101110
}>;
102111
}
@@ -138,8 +147,18 @@ async function run() {
138147
break;
139148
}
140149
const parsedArgs = advParseArgs(args, "upload");
141-
const { repoName, localFolder, repoType, revision, fromEmpty, fromRevision, token, quiet, commitMessage } =
142-
parsedArgs;
150+
const {
151+
repoName,
152+
localFolder,
153+
repoType,
154+
revision,
155+
fromEmpty,
156+
fromRevision,
157+
token,
158+
quiet,
159+
commitMessage,
160+
hubUrl,
161+
} = parsedArgs;
143162

144163
if (revision && (fromEmpty || fromRevision)) {
145164
await createBranch({
@@ -149,6 +168,7 @@ async function run() {
149168
revision: fromRevision,
150169
empty: fromEmpty ? true : undefined,
151170
overwrite: true,
171+
hubUrl,
152172
});
153173
}
154174

@@ -159,6 +179,7 @@ async function run() {
159179
accessToken: token,
160180
commitTitle: commitMessage?.trim().split("\n")[0],
161181
commitDescription: commitMessage?.trim().split("\n").slice(1).join("\n").trim(),
182+
hubUrl,
162183
})) {
163184
if (!quiet) {
164185
console.log(event);
@@ -176,6 +197,7 @@ function usage(commandName: Command) {
176197
const command = commands[commandName];
177198

178199
return `${commandName} ${(command.args || [])
200+
.filter((arg) => !arg.hidden)
179201
.map((arg) => {
180202
if (arg.positional) {
181203
if (arg.required) {
@@ -205,11 +227,11 @@ function detailedUsage(commandName: Command) {
205227
ret += `\n`;
206228
}
207229

208-
if (command.args.some((p) => !p.positional)) {
230+
if (command.args.some((p) => !p.positional && !p.hidden)) {
209231
ret += `Options:\n`;
210232

211233
for (const arg of command.args) {
212-
if (!arg.positional) {
234+
if (!arg.positional && !arg.hidden) {
213235
ret += ` --${arg.name}${arg.short ? `, -${arg.short}` : ""}: ${arg.description}\n`;
214236
}
215237
}

0 commit comments

Comments
 (0)