Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't create no flag commands. #13

Open
wh1tecat-nya opened this issue Dec 4, 2019 · 1 comment · May be fixed by #51
Open

can't create no flag commands. #13

wh1tecat-nya opened this issue Dec 4, 2019 · 1 comment · May be fixed by #51

Comments

@wh1tecat-nya
Copy link

I tried create simple command that uses only arguments (like a file path).
But if do not assignment flag property for makeCommand function 2nd arguments, get an Error: TypeError: t2 is not a function

I did investigation for this.

makeCommand option of flag is Partial type intype CommandSpec.

catacli/src/command.ts

Lines 5 to 26 in 14d54bd

export type CommandSpec<
N extends string,
F extends (args: string[]) => any,
P extends (args: string[]) => any
> = {
name: N;
description?: string;
version?: string;
usage?: string;
flag?: F;
positionalArguments?: P;
handler?: F extends (args: string[]) => infer V
? P extends (args: string[]) => infer U
? (
args: U,
flags: V,
helpFn?: Function,
metaInfo?: { spec?: CommandSpec<N, F, P>; rawArgs?: string[] }
) => any
: never
: never;
};

But inside of makeCommand function, spec.flag is calling as a function.

catacli/src/command.ts

Lines 45 to 54 in 14d54bd

export function makeCommand<
N extends string,
T extends (args: string[]) => any,
P extends (args: string[]) => any
>(spec: CommandSpec<N, T, P>, showHelp = defaultHelp): Command {
return (args: string[], parentSpec) => {
const parser = showHelp
? reduceFlag(defaultHelpFlag, spec.flag)
: spec.flag;
const flags = parser(args);

In short, if do not assignment flag property, spec.flag is undefined but called as as function.
then get an Error: TypeError: t2 is not a function.

that is correct?
and if correct this, may i try create a pull request?

@akito0107
Copy link
Owner

@wh1tecat-nya
Thank you for reporting.

that is correct?

I confirmed this issue and this is a bug. I didn't care about no flag scenario, sorry.

and if correct this, may i try create a pull request?

PRs are very welcome and thank you for contribution !

akito0107 added a commit that referenced this issue Mar 31, 2020
@akito0107 akito0107 linked a pull request Mar 31, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants