Skip to content

Commit

Permalink
fix: allow multipart flags
Browse files Browse the repository at this point in the history
Fixes a bug where the usage of a multipart flag (e.g. `--foo.bar`) results in that flag being
interpretted as both a flag and a positional parameter.

Signed-off-by: Marty Jones <mjones721@bloomberg.net>
  • Loading branch information
Marty Jones committed Dec 11, 2024
1 parent 7898563 commit e6e6973
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/parameter/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function findFlagsByArgument<CONTEXT extends CommandContext>(
return [];
}

const FLAG_NAME_VALUE_PATTERN = /^--([a-z][a-z-]+)=(.+)$/i;
const FLAG_NAME_VALUE_PATTERN = /^--([a-z][a-z-\.]+)=(.+)$/i;
const ALIAS_VALUE_PATTERN = /^-([a-z])=(.+)$/i;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
:::: formatDocumentationForFlagParameters / no flags
-h --help Print help information and exit
 -- All subsequent inputs should be interpreted as arguments
:::: formatDocumentationForFlagParameters / parsed / multipart flag
 --multi.part required parsed flag
-h --help Print help information and exit
 -- All subsequent inputs should be interpreted as arguments
:::: formatDocumentationForFlagParameters / parsed / multiple parsed flags
 --requiredParsed required parsed flag
 --requiredParsedWithLongerName required parsed flag with longer name
Expand Down
25 changes: 25 additions & 0 deletions packages/core/tests/parameter/flag/formatting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,5 +728,30 @@ describe("formatDocumentationForFlagParameters", function () {
// THEN
compareToBaseline(this, StringArrayBaselineFormat, lines);
});

it("multipart flag", function () {
// GIVEN
type Positional = [];
type Flags = {
readonly "multi.part": string;
};

const parameters: TypedCommandParameters<Flags, Positional, CommandContext> = {
flags: {
"multi.part": {
kind: "parsed",
parse: String,
brief: "required parsed flag",
},
},
positional: { kind: "tuple", parameters: [] },
};

// WHEN
const lines = formatDocumentationForFlagParameters(parameters.flags, parameters.aliases ?? {}, defaultArgs);

// THEN
compareToBaseline(this, StringArrayBaselineFormat, lines);
});
});
});

0 comments on commit e6e6973

Please sign in to comment.