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

custom flag type doesn't respect required set in a custom flag #783

Closed
cristiand391 opened this issue Sep 12, 2023 · 0 comments
Closed

custom flag type doesn't respect required set in a custom flag #783

cristiand391 opened this issue Sep 12, 2023 · 0 comments

Comments

@cristiand391
Copy link
Member

cristiand391 commented Sep 12, 2023

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

  1. clone this branch of sf-plugin-api: https://github.com/cristiand391/sf-plugin-api/tree/cd%2Foclif-required-flag
  2. see target-org type is (property) 'target-org': OptionFlag<Org, CustomOptions> org api command
  3. Delete this line: https://github.com/cristiand391/sf-plugin-api/blob/deb78ab0eccd81ba9043760d7d4fe9d36bb2b474/src/commands/org/api.ts#L39
  4. 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:

Screenshot 2023-09-12 at 12 36 07

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

No branches or pull requests

2 participants