Skip to content

Commit

Permalink
Fixed option builder ignoring names, fixed positionals vanishing from…
Browse files Browse the repository at this point in the history
… options, added subcommands
  • Loading branch information
Sukairo-02 committed Jul 2, 2024
1 parent 0602def commit 1f26761
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@drizzle-team/brocli",
"type": "module",
"author": "Drizzle Team",
"version": "0.3.0",
"version": "0.4.0",
"description": "Typed CLI command runner",
"license": "Apache-2.0",
"sideEffects": false,
Expand Down
12 changes: 11 additions & 1 deletion src/command-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ const validateOptions = <TOptionConfig extends Record<string, GenericBuilderInte
for (const [key, value] of cfgEntries) {
const cfg = value._.config;

if (cfg.type === 'positional') continue;
if (cfg.type === 'positional') {
entries.push([key, { config: cfg, $output: undefined as any }]);

continue;
}

const reservedNames = ['--help', '-h', '--version', '-v'];

Expand Down Expand Up @@ -483,6 +487,12 @@ const parseArg = (
return true;
}

if (!hasEq) {
data = true;
skipNext = false;
return true;
}

throw invalidBooleanSyntax(match);
} else {
const match = names.find((name) => name === namePart);
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ export type {
AnyRawCommand,
BroCliConfig,
Command,
CommandCandidate,
CommandHandler,
GenericCommandHandler,
HelpHandler,
InnerCommandParseRes,
RawCommand,
RawCommandWithPositionals,
RawCommandWithSubcommands,
Expand Down
4 changes: 2 additions & 2 deletions src/option-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export function number(): Omit<
OptionType | 'enum'
>;
export function number<TName extends string>(name?: TName) {
return typeof name === 'number' ? new OptionBuilderBase().number(name) : new OptionBuilderBase().number();
return typeof name === 'string' ? new OptionBuilderBase().number(name) : new OptionBuilderBase().number();
}

export function boolean<TName extends string>(
Expand Down Expand Up @@ -442,7 +442,7 @@ export function positional(): Omit<
OptionType | 'min' | 'max' | 'int' | 'alias'
>;
export function positional(displayName?: string) {
return typeof displayName === 'number'
return typeof displayName === 'string'
? new OptionBuilderBase().positional(displayName)
: new OptionBuilderBase().positional();
}

0 comments on commit 1f26761

Please sign in to comment.