Skip to content

Commit 0fa9af7

Browse files
committed
cli fixes
1 parent 3533e2e commit 0fa9af7

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,8 @@
3030
"vite": "^5.0.2",
3131
"vitest": "^0.34.6",
3232
"webdriverio": "^8.6.7"
33+
},
34+
"dependencies": {
35+
"@huggingface/hub": "link:packages/hub"
3336
}
3437
}

packages/hub/cli.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ type Command = keyof typeof commands;
102102
103103
async function run() {
104104
switch (command) {
105+
case undefined:
106+
case "--help":
105107
case "help": {
106108
const positionals = parseArgs({ allowPositionals: true, args }).positionals;
107109
@@ -117,11 +119,17 @@ async function run() {
117119
.map(([name, { description }]) => `- ${usage(name)}: ${description}`)
118120
.join("\n")
119121
);
122+
123+
console.log("\nTo get help on a specific command, run `hfjs help <command>` or `hfjs <command> --help`");
124+
125+
if (command === undefined) {
126+
process.exitCode = 1;
127+
}
120128
break;
121129
}
122130

123131
case "upload": {
124-
if (args[1] === "--help" || args[1] === "-h") {
132+
if (args[0] === "--help" || args[0] === "-h") {
125133
console.log(usage("upload"));
126134
break;
127135
}
@@ -171,7 +179,7 @@ function usage(commandName: Command) {
171179
}
172180
return `[--${arg.name} ${arg.enum ? `{${arg.enum.join(",")}}` : arg.name.toLocaleUpperCase()}]`;
173181
})
174-
.join("")}`.trim();
182+
.join(" ")}`.trim();
175183
}
176184

177185
function detailedUsage(commandName: Command) {
@@ -219,8 +227,9 @@ function advParseArgs<C extends Command>(
219227
.map((arg) => {
220228
const option = {
221229
name: arg.name,
222-
short: arg.short,
230+
...(arg.short && { short: arg.short }),
223231
type: arg.boolean ? "boolean" : "string",
232+
default: typeof arg.default === "function" ? arg.default() : arg.default,
224233
} as const;
225234
return [arg.name, option];
226235
})

packages/hub/tsup.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { Options } from "tsup";
22

3-
const baseConfig: Options = {
3+
const baseConfig = {
44
entry: ["./index.ts"],
55
format: ["cjs", "esm"],
66
outDir: "dist",
77
clean: true,
8-
};
8+
} satisfies Options;
99

1010
const nodeConfig: Options = {
1111
...baseConfig,
12+
entry: [...baseConfig.entry, "./cli.ts"],
1213
platform: "node",
1314
};
1415

0 commit comments

Comments
 (0)