-
Notifications
You must be signed in to change notification settings - Fork 595
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
[ts-command-line] Parameters in CommandLineParser onExecute are undefined #4708
Comments
I'm not getting a repro of this issue. I've created a repo here with your example and invited you to it: https://github.com/iclanton/rushstack-4708-repro. Can you update that with your repro? This is the output I get from various commands (I've run this on Windows and Linux, but not Mac):
|
Hmm, it seems to be an issue with my tsconfig.json. Not sure if thats a bug, or just incorrect setup on my part, but I have updated the tsconfig.json in that repo.
|
This issue is the Comparing the TypeScript compiler output for es2021 vs es2022: class WidgetCommandLine extends ts_command_line_1.CommandLineParser {
+ _verbose;
constructor() {
super({
toolFilename: "widget",
toolDescription: 'The "widget" tool is a code sample for using the @rushstack/ts-command-line library.',
});
this.addAction(new PushAction());
}
onDefineParameters() {
// abstract
this._verbose = this.defineFlagParameter({
parameterLongName: "--verbose",
parameterShortName: "-v",
description: "Show extra logging detail",
});
}
onExecute() {
// override
console.log("WidgetCommandLine.onExecute", this._verbose);
return super.onExecute();
}
} Notice that the
To fix this issue, target <es2022, or move the parameter declarations into the export class WidgetCommandLine extends CommandLineParser {
- private _verbose!: CommandLineFlagParameter;
+ private _verbose: CommandLineFlagParameter;
public constructor() {
super({
toolFilename: "widget",
toolDescription:
'The "widget" tool is a code sample for using the @rushstack/ts-command-line library.',
});
this.addAction(new PushAction());
- }
-
- protected onDefineParameters(): void {
- // abstract
+
+ // define parameters
this._verbose = this.defineFlagParameter({
parameterLongName: "--verbose",
parameterShortName: "-v",
description: "Show extra logging detail",
});
}
protected onExecute(): Promise<void> {
// override
console.log("WidgetCommandLine.onExecute", this._verbose);
return super.onExecute();
}
} We should probably consider removing the |
Closing this out, since it seems like we've figured out the issue. |
Summary
I followed the example in the readme, trying to add a
--verbose
parameter to all actions, but in theonExecute
methodthis._verbose
is undefined.Repro steps
Expected result:
Actual result:
Details
Standard questions
Please answer these questions to help us investigate your issue more quickly:
node -v
)?The text was updated successfully, but these errors were encountered: