-
Notifications
You must be signed in to change notification settings - Fork 11
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
Changes from all commits
76e2ccc
24cf4b9
a50fc02
7c4b5fa
dba0e4b
3089130
0d83459
76b5250
010509c
5302946
a532ed1
0454ec9
7c34fc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,19 @@ 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, | ||
deprecateAliases: true, | ||
aliases: ['sfdxurlfile'], | ||
exactlyOne: ['sfdx-url-file', 'sfdx-url-stdin'], | ||
}), | ||
'sfdx-url-stdin': Flags.file({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdonnalley, question: It sounds to me like There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
char: 'u', | ||
summary: messages.getMessage('flags.sfdx-url-stdin.summary'), | ||
required: false, | ||
deprecateAliases: true, | ||
aliases: ['sfdxurlstdin'], | ||
allowStdin: 'only', | ||
exactlyOne: ['sfdx-url-file', 'sfdx-url-stdin'], | ||
}), | ||
'set-default-dev-hub': Flags.boolean({ | ||
char: 'd', | ||
|
@@ -71,15 +81,21 @@ export default class LoginSfdxUrl extends AuthBaseCommand<AuthFields> { | |
if (await this.shouldExitCommand(flags['no-prompt'])) return {}; | ||
|
||
const authFile = flags['sfdx-url-file']; | ||
const authStdin = flags['sfdx-url-stdin']; | ||
let sfdxAuthUrl: string; | ||
|
||
const sfdxAuthUrl = authFile.endsWith('.json') | ||
? await getUrlFromJson(authFile) | ||
: await fs.readFile(authFile, 'utf8'); | ||
if (authFile) { | ||
sfdxAuthUrl = authFile.endsWith('.json') ? await getUrlFromJson(authFile) : await fs.readFile(authFile, 'utf8'); | ||
|
||
if (!sfdxAuthUrl) { | ||
throw new Error( | ||
`Error getting the auth URL from file ${authFile}. Please ensure it meets the description shown in the documentation for this command.` | ||
); | ||
if (!sfdxAuthUrl) { | ||
throw new Error( | ||
`Error getting the auth URL from file ${authFile}. Please ensure it meets the description shown in the documentation for this command.` | ||
); | ||
} | ||
} else if (authStdin) { | ||
sfdxAuthUrl = authStdin; | ||
} else { | ||
throw new Error('SFDX Auth URL not found.'); | ||
} | ||
|
||
const oauth2Options = AuthInfo.parseSfdxAuthUrl(sfdxAuthUrl); | ||
|
There was a problem hiding this comment.
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
andsfdx-url-stdin
to ensure that people provide one of thoseDoing 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 bothThere was a problem hiding this comment.
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.There was a problem hiding this comment.
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 inexactlyOne
so there's not actually a need for both - you only needexactlyOne
on both flagsSorry about that - should have tested it all out before asking you to make a change!
There was a problem hiding this comment.
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 👍