Skip to content

Commit

Permalink
add linter rule prohibiting fmt.Print and fix cmd/
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <[email protected]>
  • Loading branch information
asraa committed Sep 19, 2022
1 parent 4780a8c commit ff7c5b6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ linters:
- gosimple
- unused
- typecheck
- forbidigo
3 changes: 2 additions & 1 deletion cmd/tuf-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"os"

docopt "github.com/flynn/go-docopt"
tuf "github.com/theupdateframework/go-tuf/client"
Expand Down Expand Up @@ -32,7 +33,7 @@ See "tuf-client help <command>" 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 <command>`
cmd = cmdArgs[0]
Expand Down
5 changes: 3 additions & 2 deletions cmd/tuf/gen_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"
"time"

"github.com/flynn/go-docopt"
Expand Down Expand Up @@ -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
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion cmd/tuf/get_threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"

"github.com/flynn/go-docopt"
"github.com/theupdateframework/go-tuf"
Expand All @@ -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
}
8 changes: 6 additions & 2 deletions cmd/tuf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ See "tuf help <command>" 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 <command>`
cmd = cmdArgs[0]
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/tuf/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"

"github.com/flynn/go-docopt"
"github.com/theupdateframework/go-tuf"
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion cmd/tuf/set_threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"os"
"strconv"

"github.com/flynn/go-docopt"
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cmd/tuf/sign_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff7c5b6

Please sign in to comment.