Skip to content

Conversation

@mcpherrinm
Copy link
Contributor

This splits the logic into a cli, which handles parsing command line args and
reading files, and a terminal abstraction for handling user input and ouput.

All uses of os.Exit are removed in favor of returning errors.

Overall this enables better testing and reuse of code. Previously we had to
rely on external unit testing for CLI tests, which are harder to write tests.

defer tty.Close()
}

tty.WriteString("Enter password")

Choose a reason for hiding this comment

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

Error return value of tty.WriteString is not checked (from errcheck)


tty.WriteString("Enter password")
if prompt != "" {
tty.WriteString(fmt.Sprintf(" for entry [%s]", prompt))

Choose a reason for hiding this comment

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

Error return value of tty.WriteString is not checked (from errcheck)

if prompt != "" {
tty.WriteString(fmt.Sprintf(" for entry [%s]", prompt))
}
tty.WriteString(": ")

Choose a reason for hiding this comment

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

Error return value of tty.WriteString is not checked (from errcheck)

result.CertificateRequestInfo = cri
for _, cert := range connState.PeerCertificates {
if *connectPem {
pem.Encode(stdout, lib.EncodeX509ToPEM(cert, nil))

Choose a reason for hiding this comment

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

Error return value of pem.Encode is not checked (from errcheck)


func inputFiles(fileNames []string) ([]*os.File, error) {
var files []*os.File
if fileNames != nil {

Choose a reason for hiding this comment

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

S1031: unnecessary nil check around range (from gosimple)

tty.SetDefaultPassword(*dumpPassword)
}

files, err := inputFiles(*dumpFiles)

Choose a reason for hiding this comment

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

SA4006: this value of err is never used (from staticcheck)

cli/cli.go Outdated

file, err := inputFile(*verifyFile)
if err != nil {
fmt.Fprintf(errOut, err.Error())

Choose a reason for hiding this comment

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

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (from staticcheck)

This splits the logic into a cli, which handles parsing command line args and
reading files, and a terminal abstraction for handling user input and ouput.

All uses of os.Exit are removed in favor of returning errors.

Overall this enables better testing and reuse of code.  Previously we had to
rely on external unit testing for CLI tests, which are harder to write tests.
Copy link
Contributor

@mbyczkowski mbyczkowski left a comment

Choose a reason for hiding this comment

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

This seems like a good refactoring to me. golintci nits can be handled in a separate PRs. @mcpherrinm do you think it makes sense to merge #178 first and then rebase this PR or the other way around?

@mcpherrinm mcpherrinm merged commit 513c01d into master Feb 6, 2020
@mcpherrinm mcpherrinm deleted the refactor branch February 6, 2020 23:10
@mcpherrinm
Copy link
Contributor Author

mcpherrinm commented Feb 6, 2020

let's merge this and keep improving from there; I'm not sure #178 is ready for merge yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants