-
Notifications
You must be signed in to change notification settings - Fork 73
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
fix: retain enable json flag get/set apply flag at parse #460
Conversation
src/command.ts
Outdated
@@ -246,7 +246,7 @@ export default abstract class Command { | |||
if (!options) options = this.constructor as any | |||
const opts = {context: this, ...options} | |||
// the spread operator doesn't work with getters so we have to manually add it here | |||
opts.flags = options?.flags | |||
opts.flags = (this.ctor.enableJsonFlag ? {...options?.flags, ...jsonFlag} : options?.flags) as Interfaces.FlagInput<F> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to also change enableJsonFlag
from a getter/setter to static property. Otherwise, it'll still allow the --json
flag when a subclass has set enableJsonFlag
to false
with getter/setter:
~/code/global-flags » bin/dev status --json
undefined
with static property
~/code/global-flags » bin/dev status --json
Error: Unexpected argument: --json
See more help with --help
at validateArgs (/Users/mdonnalley/repos/oclif/core/lib/parser/validate.js:11:19)
at Object.validate (/Users/mdonnalley/repos/oclif/core/lib/parser/validate.js:78:5)
at Object.parse (/Users/mdonnalley/repos/oclif/core/lib/parser/index.js:30:7)
at async Status.run (/Users/mdonnalley/code/global-flags/src/commands/status.ts:82:20)
at async Status._run (/Users/mdonnalley/repos/oclif/core/lib/command.js:65:22)
at async Config.runCommand (/Users/mdonnalley/repos/oclif/core/lib/config/config.js:270:25)
at async Object.run (/Users/mdonnalley/repos/oclif/core/lib/main.js:76:5)
Never mind. As I was testing this I realized that deferring the json inclusion to parse
means that help isn't ever aware of the json flag... which is why the tests were failing when you tried the solution I suggested.
So now that I know that, I think your original solution might be the best path forward
static set enableJsonFlag(value: boolean) {
this._enableJsonFlag = value
if (value === true) {
this.globalFlags = jsonFlag
} else {
// @ts-ignore
delete this.globalFlags.json
// @ts-ignore
delete this.flags.json
}
}
Sorry for being difficult!
QA
Subclass extends Parent Subclass with |
No description provided.