Skip to content

Commit

Permalink
fix(usage): render valueHint for positional args
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 14, 2024
1 parent 0e73aad commit dbd1d92
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions playground/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default defineCommand({
type: "positional",
required: false,
description: "path to output directory",
default: ".output",
},
},
run({ args }) {
Expand Down
6 changes: 3 additions & 3 deletions playground/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export default defineCommand({
type: "boolean",
description: "Dry run the deployment process",
},
outputDir: {
provider: {
type: "positional",
description: "Path to the build output directory",
default: ".output",
description: "Deployment provider",
valueHint: "foo|bar|baz|qux",
},
},
run({ args }) {
Expand Down
8 changes: 6 additions & 2 deletions src/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export async function renderUsage<T extends ArgsDef = ArgsDef>(
const name = arg.name.toUpperCase();
const isRequired = arg.required !== false && arg.default === undefined;
// (isRequired ? " (required)" : " (optional)"
const usageHint = arg.default ? `="${arg.default}"` : "";
posLines.push(["`" + name + usageHint + "`", arg.description || ""]);
const defaultHint = arg.default ? `="${arg.default}"` : "";
posLines.push([
"`" + name + defaultHint + "`",
arg.description || "",
arg.valueHint ? `<${arg.valueHint}>` : "",
]);
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
} else {
const isRequired = arg.required === true && arg.default === undefined;
Expand Down

0 comments on commit dbd1d92

Please sign in to comment.