diff --git a/.golangci.yml b/.golangci.yml index 6e8bf3c8..570c05d6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -13,3 +13,4 @@ linters: - gosimple - unused - typecheck + - forbidigo diff --git a/cmd/tuf-client/main.go b/cmd/tuf-client/main.go index 15d03fad..25a32005 100644 --- a/cmd/tuf-client/main.go +++ b/cmd/tuf-client/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "os" docopt "github.com/flynn/go-docopt" tuf "github.com/theupdateframework/go-tuf/client" @@ -32,7 +33,7 @@ See "tuf-client help " for more information on a specific command. if cmd == "help" { if len(cmdArgs) == 0 { // `tuf-client help` - fmt.Println(usage) + fmt.Fprint(os.Stderr, usage) return } else { // `tuf-client help ` cmd = cmdArgs[0] diff --git a/cmd/tuf/gen_key.go b/cmd/tuf/gen_key.go index bd4334ae..2ad77a58 100644 --- a/cmd/tuf/gen_key.go +++ b/cmd/tuf/gen_key.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "time" "github.com/flynn/go-docopt" @@ -39,7 +40,7 @@ func cmdGenKey(args *docopt.Args, repo *tuf.Repo) error { string(data.KeySchemeRSASSA_PSS_SHA256): keyScheme = data.KeyScheme(t) default: - fmt.Println("Using default key scheme", keyScheme) + fmt.Fprint(os.Stderr, "Using default key scheme", keyScheme) } var err error @@ -57,7 +58,7 @@ func cmdGenKey(args *docopt.Args, repo *tuf.Repo) error { return err } for _, id := range keyids { - fmt.Println("Generated", role, keyScheme, "key with ID", id) + fmt.Fprintf(os.Stdout, "Generated %s %s key with ID %s", role, keyScheme, id) } return nil } diff --git a/cmd/tuf/get_threshold.go b/cmd/tuf/get_threshold.go index e40ec26e..a0d78fdd 100644 --- a/cmd/tuf/get_threshold.go +++ b/cmd/tuf/get_threshold.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "github.com/flynn/go-docopt" "github.com/theupdateframework/go-tuf" @@ -23,6 +24,6 @@ func cmdGetThreshold(args *docopt.Args, repo *tuf.Repo) error { return err } - fmt.Println("The threshold for", role, "role is", threshold) + fmt.Fprintf(os.Stdout, "The threshold for %s role is %d", role, threshold) return nil } diff --git a/cmd/tuf/main.go b/cmd/tuf/main.go index f2b73972..6ee220b2 100644 --- a/cmd/tuf/main.go +++ b/cmd/tuf/main.go @@ -58,7 +58,7 @@ See "tuf help " for more information on a specific command if cmd == "help" { if len(cmdArgs) == 0 { // `tuf help` - fmt.Println(usage) + fmt.Fprint(os.Stderr, usage) return } else { // `tuf help ` cmd = cmdArgs[0] @@ -115,7 +115,11 @@ func runCommand(name string, args []string, dir string, insecure bool) error { if !insecure { p = getPassphrase } - repo, err := tuf.NewRepo(tuf.FileSystemStore(dir, p)) + logger := log.New(os.Stdout, "", 0) + storeOpts := tuf.StoreOpts{Logger: logger, PassFunc: p} + + repo, err := tuf.NewRepoWithOpts(tuf.FileSystemStoreWithOpts(dir, storeOpts), + tuf.WithLogger(logger)) if err != nil { return err } diff --git a/cmd/tuf/payload.go b/cmd/tuf/payload.go index 8cc0c2ff..3ae2c891 100644 --- a/cmd/tuf/payload.go +++ b/cmd/tuf/payload.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "github.com/flynn/go-docopt" "github.com/theupdateframework/go-tuf" @@ -20,6 +21,6 @@ func cmdPayload(args *docopt.Args, repo *tuf.Repo) error { if err != nil { return err } - fmt.Print(string(p)) + fmt.Fprint(os.Stdout, string(p)) return nil } diff --git a/cmd/tuf/set_threshold.go b/cmd/tuf/set_threshold.go index 57754d24..29149ff9 100644 --- a/cmd/tuf/set_threshold.go +++ b/cmd/tuf/set_threshold.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "strconv" "github.com/flynn/go-docopt" @@ -28,6 +29,6 @@ func cmdSetThreshold(args *docopt.Args, repo *tuf.Repo) error { return err } - fmt.Println("The threshold for", role, "role is now", threshold) + fmt.Fprintf(os.Stdout, "The threshold for %s role is now %d", role, threshold) return nil } diff --git a/cmd/tuf/sign_payload.go b/cmd/tuf/sign_payload.go index 8da5642b..6772972c 100644 --- a/cmd/tuf/sign_payload.go +++ b/cmd/tuf/sign_payload.go @@ -36,7 +36,7 @@ func cmdSignPayload(args *docopt.Args, repo *tuf.Repo) error { if err != nil { return err } - fmt.Print(string(bytes)) + fmt.Fprint(os.Stdout, string(bytes)) fmt.Fprintln(os.Stderr, "tuf: signed with", numKeys, "key(s)") return nil