diff --git a/src/help/__tests__/help.spec.ts b/src/help/__tests__/help.spec.ts index adb2b99..98d565e 100644 --- a/src/help/__tests__/help.spec.ts +++ b/src/help/__tests__/help.spec.ts @@ -48,6 +48,16 @@ describe("help", () => { return expect(strip(await getHelp(prog))).toMatchSnapshot() }) + it("should display help for a program with options in order given", async () => { + prog + .argument("", "Mandarory foo arg") + .argument("[other]", "Other args") + .option("-f, --file ", " Output file") + .option("-e, --ext ", " extension file") + return expect(strip(await getHelp(prog))).toMatchSnapshot() + }) + + it("should display help for a program having at least one command (with args & options)", async () => { prog .command("test-command", "Test command") diff --git a/src/help/templates/command.ts b/src/help/templates/command.ts index 83de126..07059d1 100644 --- a/src/help/templates/command.ts +++ b/src/help/templates/command.ts @@ -10,7 +10,7 @@ import sortBy from "lodash/sortBy" export const command: Template = async (ctx: TemplateContext) => { const { cmd, globalOptions: globalFlags, eol, eol3, colorize, tpl } = ctx - const options = sortBy(cmd!.options, "name"), + const options = sortBy(cmd!.options, "required"), globalOptions = Array.from(globalFlags.keys()) const help =