custom flag type doesn't respect `required` set in a custom flag
cristiand391 opened this issue · comments
Describe the bug
If I have a custom flag with required: true
and use it in a command, its type is <T | undefined>
.
To Reproduce
- clone this branch of sf-plugin-api: https://github.com/cristiand391/sf-plugin-api/tree/cd%2Foclif-required-flag
- see
target-org
type is(property) 'target-org': OptionFlag<Org, CustomOptions>
org api command - Delete this line: https://github.com/cristiand391/sf-plugin-api/blob/deb78ab0eccd81ba9043760d7d4fe9d36bb2b474/src/commands/org/api.ts#L39
target-org
type now is:(property) 'target-org': OptionFlag<Org | undefined, CustomOptions>
requiredOrgFlag
already sets required: true
so we shouldn't need to set required
again:
https://github.com/salesforcecli/sf-plugins-core/blob/c43456953f5fb14bb64d1cc72f84c78c2c211088/src/flags/orgFlags.ts#L154
For comparision, I added a two flags in the org api
command:
https://github.com/cristiand391/sf-plugin-api/blob/deb78ab0eccd81ba9043760d7d4fe9d36bb2b474/src/commands/org/api.ts#L16-L23
lalaFlag
is a string flag, testFlag
is a custom flag and both set required: true
, if you check their types here:
https://github.com/cristiand391/sf-plugin-api/blob/deb78ab0eccd81ba9043760d7d4fe9d36bb2b474/src/commands/org/api.ts#L31-L32
you can see lalaFlag
respects required:true
:
(property) lala: OptionFlag<string, CustomOptions>
and testFlag
doesn't:
(property) test: OptionFlag<string | undefined, CustomOptions>
Expected behavior
custom flag type should recognize when required
is set.
Environment (please complete the following information):
- OS & version: macos ventura
- Shell/terminal & version zsh/alacritty
Additional context
We've been manually setting required
in our plugins:
https://github.com/search?q=org%3Asalesforcecli+%2FFlags%5C.requiredOrg%2F+%2Frequired%3A+true%2F&type=code
You can see that required
is actually passed (see below the help text org --target-org
after required: true
is deleted in org api
), the issue seems to be only the flag type: