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

feat: allow stdin for sfdx-url #886

Merged

Conversation

k-capehart
Copy link

@k-capehart k-capehart commented Dec 13, 2023

What does this PR do?

  • oclif has been updated to include a new option for flags: allowStdin
  • Another oclif update allows a flag to be designated as stdin 'only', meaning that it will error out if anything other than the '-' value is provided
  • A new flag has been introduced per recommendation called --sfdx-url-stdin and has allowStdin: 'only'
  • This means --sfdx-url-file is no longer required, so an error is thrown if neither --sfdx-url-stdin or --sfdx-url-file are given
  • Original discussion on this solution found here: Allow flags to read its value from stdin oclif/core#761

$ echo url | sf org login sfdx-url --sfdx-url-stdin -

What issues does this PR fix or reference?

closes: forcedotcom/cli#2120
[skip-validate-pr]

@k-capehart k-capehart requested a review from a team as a code owner December 13, 2023 21:29
Copy link
Contributor

@jshackell-sfdc jshackell-sfdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a light edit. This is no guarantee that we'll accept your contribution! But I noticed it and thought I'd give you some suggestions. Thx.

messages/sfdxurl.store.md Outdated Show resolved Hide resolved
messages/sfdxurl.store.md Outdated Show resolved Hide resolved
messages/sfdxurl.store.md Outdated Show resolved Hide resolved
messages/sfdxurl.store.md Outdated Show resolved Hide resolved
Kyle Capehart and others added 4 commits December 13, 2023 16:48
Co-authored-by: Juliet Shackell <[email protected]>
Co-authored-by: Juliet Shackell <[email protected]>
Co-authored-by: Juliet Shackell <[email protected]>
Co-authored-by: Juliet Shackell <[email protected]>
@mdonnalley mdonnalley added the enhancement New feature or request label Dec 14, 2023
@mdonnalley
Copy link
Contributor

@k-capehart Thanks for taking this on!

As you noted, this change would allow someone to pass the url directly to the flag. I just made a PR to oclif/core that adds an only option to allowStdin. I think we should create a separate flag for the stdin (--sfdx-url-stdin) and use allowStdin: 'only' to force users to supply the - value

That way we don't open up the possibility for people to provide the url directly

@k-capehart
Copy link
Author

@k-capehart Thanks for taking this on!

As you noted, this change would allow someone to pass the url directly to the flag. I just made a PR to oclif/core that adds an only option to allowStdin. I think we should create a separate flag for the stdin (--sfdx-url-stdin) and use allowStdin: 'only' to force users to supply the - value

That way we don't open up the possibility for people to provide the url directly

Perfect! I'll update this PR to reflect that new change in oclif. Thanks.

@mdonnalley
Copy link
Contributor

@k-capehart FYI, I merged the oclif/core PR. Changes should be available in 3.16.0

@k-capehart
Copy link
Author

@k-capehart FYI, I merged the oclif/core PR. Changes should be available in 3.16.0

@mdonnalley Thanks for your help. This PR has been updated to reflect the new changes and is ready for review now.

@k-capehart
Copy link
Author

@jshackell-sfdc Also, I updated the documentation if you don't mind reviewing again. Thank you!

@@ -33,10 +33,18 @@ export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> {
'sfdx-url-file': Flags.file({
char: 'f',
summary: messages.getMessage('flags.sfdx-url-file.summary'),
required: true,
required: false,
Copy link
Contributor

@mdonnalley mdonnalley Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add this to both sfdx-url-file and sfdx-url-stdin to ensure that people provide one of those

exactlyOne: ['sfdx-url-file', 'sfdx-url-stdin']

Doing that would allow you to drop the validation logic you have on lines 88-96

We should also add exclusive: ['sfdx-url-stdin'] to make sure that people don't provide both

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdonnalley I added these suggestions but kept the validation logic, otherwise I get a compiler error that sfdxAuthUrl could be undefined. I think that's because its not smart enough to know that one of the flags are guaranteed to be provided. Let me know if you know a work-around, but I think that's consistent with other implementations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@k-capehart I think exclusive is implied in exactlyOne so there's not actually a need for both - you only need exactlyOne on both flags

Sorry about that - should have tested it all out before asking you to make a change!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdonnalley Oh makes sense, that explains the repetition in error messages I was seeing. I removed it 👍

deprecateAliases: true,
aliases: ['sfdxurlfile'],
}),
'sfdx-url-stdin': Flags.file({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add exclusive: ['sfdx-url-file'] to make sure that people don't provide both

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdonnalley, question: It sounds to me like --sfdx-url-stdin can take only one value (-), and if it's present then the user is doing the piping-through-stdin thing. So wouldn't it make more sense to make --sfdx-url-stdin a Boolean flag? Or maybe I'm missing something.

Copy link
Author

@k-capehart k-capehart Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can provide some context, this is what I based the solution on: oclif/core#761 (comment)

In this case, the value should always be - but that is consistent with CLI standards because oclif requires the - value in order to read from standard input.

Co-authored-by: Juliet Shackell <[email protected]>
Co-authored-by: Juliet Shackell <[email protected]>
@k-capehart
Copy link
Author

@mdonnalley @jshackell-sfdc I appreciate you both! It's exciting to get this one working.

@mdonnalley
Copy link
Contributor

mdonnalley commented Jan 8, 2024

QA

Setup:

  • pulled changes
  • linked to sf
  • put auth url into auth.txt and auth.json file

echo <URL> | sf org login sfdx-url --sfdx-url-stdin -
echo <URL> | sf org login sfdx-url --sfdx-url-stdin throws validation error
sf org login sfdx-url --sfdx-url-file auth.txt
sf org login sfdx-url --sfdx-url-file auth.json
sf org login sfdx-url --sfdx-url-file auth.txt --sfdx-url-stdin - throws validation error
sf org login sfdx-url throws validation error

Great work @k-capehart 🏆

@mdonnalley mdonnalley changed the base branch from main to mdonnalley/886 January 8, 2024 22:01
@mdonnalley
Copy link
Contributor

@k-capehart I'm going to merge this into a separate feature branch first so that all our integration tests can run. Once those pass I'll merge to main

@mdonnalley mdonnalley merged commit 38220ca into salesforcecli:mdonnalley/886 Jan 8, 2024
1 check passed
mdonnalley added a commit that referenced this pull request Jan 8, 2024
* feat: allow stdin for sfdx-url

* Update messages/sfdxurl.store.md



* Update messages/sfdxurl.store.md



* Update messages/sfdxurl.store.md



* Update messages/sfdxurl.store.md



* feat: create new --sfdx-url-stdin flag

* feat: remove unnecessary error

* feat: allowStdin set to 'only'

* Update messages/sfdxurl.store.md



* feat: add suggestions to make flags exclusive and required

* feat: remove exclusive option, as it is implied with exactlyOne

* Update messages/sfdxurl.store.md



---------

Co-authored-by: Kyle Capehart <[email protected]>
Co-authored-by: Juliet Shackell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

enable sfdx auth:login:sfdx-url to read the url from stdin
3 participants