-
Notifications
You must be signed in to change notification settings - Fork 84
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
fix(client): prefer CLI arguments, following OpenSSH behaviour #45
Merged
+17
−8
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ed016ea
fix(client): prefer CLI args
TheoTechnicguy 6300714
fix(client): prefer config port over default
TheoTechnicguy 0012b92
fix(client): prefer config hostname over CLI
TheoTechnicguy 732da5a
Merge branch 'main' into iss35
TheoTechnicguy 1c216c7
refactor(client): port comment typo
TheoTechnicguy 274c10b
refactor(client): review changes
TheoTechnicguy d11b7fb
Revert "refactor(client): review changes"
TheoTechnicguy 5798137
refactor(client): corrected review changes
TheoTechnicguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,9 +400,6 @@ func mainWithStatusCode() int { | |
} | ||
|
||
urlHostname, urlPort := parsedUrl.Hostname(), parsedUrl.Port() | ||
if urlPort == "" { | ||
urlPort = "443" | ||
} | ||
|
||
configHostname, configPort, configUser, configAuthMethods, err := ssh3.GetConfigForHost(urlHostname, sshConfig) | ||
if err != nil { | ||
|
@@ -417,13 +414,25 @@ func mainWithStatusCode() int { | |
|
||
hostnameIsAnIP := net.ParseIP(hostname) != nil | ||
|
||
port := configPort | ||
if port == -1 && urlPort != "" { | ||
port, err = strconv.Atoi(urlPort) | ||
if err != nil { | ||
log.Error().Msgf("invalid port number: %s: %s", urlPort, err) | ||
var port int | ||
if urlPort != "" { | ||
if parsedPort, err := strconv.Atoi(urlPort); err == nil && parsedPort < 0xffff { | ||
// There is a port in the CLI and the port is valid. Use the CLI port. | ||
port = parsedPort | ||
} else { | ||
// There is a port in the CLI but it is not valid. | ||
// use WithLevel(zerolog.FatalLevel) to log a fatal level, but let us handle | ||
// program termination. log.Fatal() exits with os.Exit(1). | ||
log.WithLevel(zerolog.FatalLevel).Str("Port", urlPort).Err(err).Msg("cli contains an invalid port") | ||
fmt.Fprintf(os.Stderr, "Bad port '%s'\n", urlPort) | ||
return -1 | ||
} | ||
} else if configPort != -1 { | ||
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. Add the comment |
||
// There is no port in the CLI, but one in a config file. Use the config port. | ||
port = configPort | ||
} else { | ||
// There is no port specified, neither in the CLI, nor in the configuration. | ||
port = 443 | ||
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. Add a comment, like |
||
} | ||
|
||
username := parsedUrl.User.Username() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would you mind inverting the two parts if this branch ? Putting the non-error case in the
if
part and the error case in theelse
part ? I think it makes it more readable because the default flow goes towards what we want to achieve. But maybe it is just me ? If you have good reasons to let it like that, let me know.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.
Sure, will do. I think this is more a go habit, as most of my
if
statements are used to check for the absence of errors 😄