-
Couldn't load subscription status.
- Fork 7.3k
1942 - api hostname flag #2058
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
1942 - api hostname flag #2058
Conversation
pkg/cmd/api/api.go
Outdated
| return filled, nil | ||
| } | ||
|
|
||
| func hostnameValidator(v interface{}) error { |
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.
Hey @wilso199, I was looking at the issue and saw your PR, so checking it out. Nice work!
What's the point of hostnameValidator taking an interface{} instead of a string? Won't the hostname always be a string?
If we decide to stick with taking an interface{}, we should do a safe type assertion to avoid a panic.
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.
@cksriprajittichai I completely agree with your suggestion. Once I get some input on the best place to put this function for it to be shared, I'll be sure to implement your change! I can't see a use case where this would take something other than a string.
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.
Hey @wilso199
Maybe utils folder would be a good place for this function. Then can be used wherever it needed.
3d19208 to
fbff1fc
Compare
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.
Thank you!
We plan to phase out the utils package, so I've moved the helper to internal/ghinstance
|
|
||
| fmt.Fprintf(opts.IO.ErrOut, "%s Logged in as %s\n", utils.GreenCheck(), utils.Bold(username)) | ||
|
|
||
| return nil |
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.
README-EDITS
Fixes #1942
I added the ability for a hostname flag to be passed in for the gh api command and updated the tests accordingly.
To validate the hostname I used a function (
hostnameValidator) that was present inpkg/cmd/auth/login.I wasn't sure of the best location to place this function so for now I copied it to the api file. If you could suggest a location, I will happily abstract the duplicated function out of both files and write some test cases to validate its behavior.Update -- I moved the
hostnameValidatorfunction toutils/utils.goand added tests. If we would rather it live somewhere else I'm happy to move it. Not sure if there is a use case for a validators.go or package to hold validation functions for inputs/flags across the project.