-
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
Allow flags to read its value from stdin #761
Comments
From Shane:
This can be mentioned in 💡 : this could be prevented via eslint rules, maybe we should start doing oclif-specific ones. |
|
Some commands could receive inputs from stdin without requiring developers to specify the flag that should receive the piped value.
Example:
|
Is anybody working on this? If not I'm going to try |
What is the plan to pass 2 flags values through stdin? |
I think there should exist only one |
@AllanOricil Nobody is currently working on this so feel free to tackle it if you'd like. I do have a few thoughts on how this should be done though.
|
I think I found a good solution for allowing N stdin flags and to introduce stdin flags. See if you agree @mdonnalley A flag with A user can specify multiple stdin flags at a time, but the stdin value that is piped to the command must have a "stdin separator", otherwise all stdin flags specified in a command receive the same value. The
If a command has N stdin flags, but the user piped less that N values, a exception is thrown because there is no way to determine which stdin flag gets which values. If a command has N stdin flags, and N values were passed, each value index matches the flag index. For example: Assuming:
All the following commands would be valid:
food-stdin[0] = foo
This would be invalid:
If a flag isn't multiple and it has
stdin flags do not work with assignments. For example, both commands shown below throw an exception
|
@AllanOricil I think that would work but I'm hesitant to recommend that approach because it's not standard CLI behavior. I think the simplest solution will be best here - even if does leave room for CLI developers to create poor user experiences. The expected behavior here would be to have a flag that could take a value (like a string) or take https://clig.dev/#arguments-and-flags
My vote is to have a |
@mdonnalley As for allowing multiple stdin values/flags in a command feature, would it be dropped then?
|
@AllanOricil Are you still working on this? I was working on something similar but looks like this is the path forward. |
Go ahead and open a PR. I did it for sfdx only and did not have time to do it for the core. I can help to review your PR and give suggestions if you need. |
@AllanOricil @mdonnalley I took a stab at a PR, feel free to pick it apart. #894 |
Is your feature request related to a problem? Please describe.
Logging this request after discussing this PR with the team:
salesforcecli/plugin-auth#765
Describe the solution you'd like
Allow flags to get their value from stdin if their value is
-
.This is a common pattern in CLIs,
oclif
supports args reading from stdin but not flags.https://clig.dev/#arguments-and-flags
Design:
off by default, flag needs
allowStdin: true
and value-
to read from stdin:Describe alternatives you've considered
We considered replacing
--sfdx-url-file
with an arg but decided this feature would:** Aditional context **
parser:
https://github.com/oclif/core/blob/main/src/parser/parse.ts
oclif also has a readStdin func to handle node 14 (still supported):
core/src/parser/parse.ts
Line 100 in 3c8cc06
The text was updated successfully, but these errors were encountered: