Skip to content

Commit

Permalink
fix(cling): Fix option list concatenation in usage description
Browse files Browse the repository at this point in the history
  • Loading branch information
simonlovesyou committed Aug 4, 2021
1 parent 06a5dfb commit 4835ae1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
35 changes: 35 additions & 0 deletions packages/cling/src/utils/mapSchemaToUsageHelp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,41 @@ describe("multiple arguments", () => {
});
});

describe("muliple options", () => {
const schemaFixture = testFixture({
options: {
help: {
type: "boolean",
},
version: {
type: 'boolean'
}
},
} as const);
it("should return the correct usage guide", () => {
expect(mapSchemaUsageToHelp(schemaFixture.get(), "lol")).toStrictEqual([
{ content: "Usage: lol [--help] [--version]", header: "lol" },
{
header: "Options",
optionList: [
{
alias: undefined,
description: undefined,
name: "help",
typeLabel: "boolean",
},
{
alias: undefined,
description: undefined,
name: "version",
typeLabel: "boolean",
},
],
},
]);
});
});

describe("single positional", () => {
const schemaFixture = testFixture({
positionals: [
Expand Down
4 changes: 2 additions & 2 deletions packages/cling/src/utils/mapSchemaToUsageHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ const schemaToUsageDescription = (
...argument,
name: argument.name ?? name,
})
)
.join(" "),
),
schema.options &&
Object.entries(schema.options).map(([name, argument]) =>
mapArgumentToLabel({
Expand All @@ -64,6 +63,7 @@ const schemaToUsageDescription = (
),
]
.filter((section) => section)
.map((section) => Array.isArray(section) ? section.join(' ') : section)
.join(" ")
.trim();
};
Expand Down

0 comments on commit 4835ae1

Please sign in to comment.