side effects of setting flag defaults
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- cli
Research direction
Start with the flag usage examples in src/commandExecution.ts and src/flags/orgFlags.ts, then trace oclif core's parser handling of defaults, required validation, and help text. Define how callers can distinguish typed flags from defaults and how required help should be rendered; done requires tests covering these cases.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
not really a feature request, just wanted to post this for others to be aware.
the way oclif handles flag defaults makes it hard to tell wether a user really typed that flag or is just a default value from flag.default: ()=>{}.
Workaround:
search for the flag in argv, like this:
https://github.com/salesforcecli/plugin-telemetry/blob/6eaedbed2bdbdf2979be9f6bcd9fad5c43ae2a5b/src/commandExecution.ts#L180-L181
so you need to carefully search for all valid flag styles (long/short, with = sep).
Example:
in sf we have a requiredHubFlag for commands that interact with Salesforce devhubs that is both required and has a default value handler:
https://github.com/salesforcecli/sf-plugins-core/blob/58d8e9a08dda865850adcdec0d791ee0195871f9/src/flags/orgFlags.ts#L175-L189
it seems the parser will first set any flag value that has a flag.default val/func defined and after that validate if flag.required: true that the flag has a value, which at the time this validation happens it's true.
some side-effects of this:
- can't determine at if a user really typed a flag or is just a default value.
- if a flag has a default and
required: true, help text is wrong ((required)when it may not be)
Describe the solution you'd like
maybe the parser could set a prop that we could check to see if it was typed or not.
Not sure what could we do with the help text.
Describe alternatives you've considered
- parsing
argv - set flags with no defaults, then handle them in the
runmethod if they weren't specified.
Additional context
We got an issue in our repo about this but some internal people noticed multiple times:
https://github.com/forcedotcom/cli/issues/2538
- Dominant language
- TypeScript
- Stars
- 316
- Forks
- 98
- Avg merge
- 12h 32m
- Merged PRs (30d)
- 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from oclif/core
-
USER STORY
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
-
BUG P2
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
BUG P3
Difficulty 3/5 1-2 days Newbie friendliness 70/100
-
BUG P2
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
BUG P3
Difficulty 3/5 1-2 days Newbie friendliness 70/100
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·