Skip to content

Commit 906ed41

Browse files
committed
Use logrus for logging
1 parent 146d6e3 commit 906ed41

File tree

16 files changed

+44
-13
lines changed

16 files changed

+44
-13
lines changed

cmd/pbcli/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package main
22

33
import (
4+
"os"
5+
46
"github.com/alecthomas/kong"
7+
log "github.com/sirupsen/logrus"
58

69
"github.com/pushbits/cli/internal/application"
710
"github.com/pushbits/cli/internal/commands"
@@ -16,8 +19,21 @@ var cmd struct {
1619
Version commands.VersionCommand `cmd:"version" aliases:"v" help:"Print the program version"`
1720
}
1821

22+
func init() {
23+
log.SetOutput(os.Stderr)
24+
log.SetLevel(log.InfoLevel)
25+
log.SetFormatter(&log.TextFormatter{
26+
DisableTimestamp: true,
27+
})
28+
}
29+
1930
func main() {
2031
ctx := kong.Parse(&cmd)
32+
33+
if cmd.Verbose {
34+
log.SetLevel(log.DebugLevel)
35+
}
36+
2137
err := ctx.Run(&cmd.Options)
2238
ctx.FatalIfErrorf(err)
2339
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.17
44

55
require (
66
github.com/alecthomas/kong v0.5.0
7+
github.com/sirupsen/logrus v1.8.1
78
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
89
)
910

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
99
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1010
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1111
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
13+
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
1214
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
1316
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1417
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18+
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1519
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1620
golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I=
1721
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

internal/api/mod.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"encoding/json"
55
"io"
66
"io/ioutil"
7-
"log"
87
"net/http"
98
"net/url"
109
"strings"
10+
11+
log "github.com/sirupsen/logrus"
1112
)
1213

1314
func buildURL(baseStr string, endpoint string) *url.URL {

internal/application/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package application
22

33
import (
4-
"log"
4+
log "github.com/sirupsen/logrus"
55

66
"github.com/pushbits/cli/internal/api"
77
"github.com/pushbits/cli/internal/options"

internal/application/delete.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package application
22

33
import (
44
"fmt"
5-
"log"
5+
6+
log "github.com/sirupsen/logrus"
67

78
"github.com/pushbits/cli/internal/api"
89
"github.com/pushbits/cli/internal/options"

internal/application/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package application
22

33
import (
4-
"log"
4+
log "github.com/sirupsen/logrus"
55

66
"github.com/pushbits/cli/internal/api"
77
"github.com/pushbits/cli/internal/options"

internal/application/show.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package application
22

33
import (
44
"fmt"
5-
"log"
5+
6+
log "github.com/sirupsen/logrus"
67

78
"github.com/pushbits/cli/internal/api"
89
"github.com/pushbits/cli/internal/options"

internal/application/update.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package application
22

33
import (
44
"fmt"
5-
"log"
5+
6+
log "github.com/sirupsen/logrus"
67

78
"github.com/pushbits/cli/internal/api"
89
"github.com/pushbits/cli/internal/options"

internal/options/mod.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package options
22

33
// Options represents the global options.
4-
type Options struct{}
4+
type Options struct {
5+
Verbose bool `short:"v" help:"Show debugging information"`
6+
}
57

68
// AuthOptions represents the options for authentication against a server.
79
type AuthOptions struct {

0 commit comments

Comments
 (0)