Skip to content

Commit 8f43f96

Browse files
committed
update with logging
1 parent 9a9e545 commit 8f43f96

4 files changed

Lines changed: 22 additions & 4 deletions

File tree

cmd/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package cmd
2+
3+
var Version = "unset"

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/dock0/ducktape
22

33
go 1.13
44

5-
require github.com/mholt/archiver/v3 v3.3.0
5+
require (
6+
github.com/akerl/timber/v2 v2.0.1
7+
github.com/mholt/archiver/v3 v3.3.0
8+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/akerl/timber/v2 v2.0.1 h1:hY4VCOJns7KsxwxP/ifSt3Rz9GZCfKewapaimObnA2E=
2+
github.com/akerl/timber/v2 v2.0.1/go.mod h1:jBjRGI2CWuvbZlrZkp1JO/X51pMlbg72NFy+Vnd59oI=
13
github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6 h1:bZ28Hqta7TFAK3Q08CMvv8y3/8ATaEqv2nGoc6yff6c=
24
github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6/go.mod h1:+lx6/Aqd1kLJ1GQfkvOnaZ1WGmLpMpbprPuIOOZX30U=
35
github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q=

main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ import (
1010
"os"
1111
"path/filepath"
1212

13+
"github.com/akerl/timber/v2/log"
1314
"github.com/mholt/archiver/v3"
15+
16+
"github.com/dock0/ducktape/cmd"
1417
)
1518

16-
var version = "0.5.0"
19+
var logger = log.NewLogger("ducktape")
1720

1821
func usage() {
1922
exampleURL := "https://example.org/download.tar.bz2"
@@ -22,7 +25,11 @@ func usage() {
2225
}
2326

2427
func getDirPath() (string, error) {
25-
return os.Executable()
28+
binPath, err := os.Executable()
29+
if err != nil {
30+
return "", err
31+
}
32+
return filepath.Dir(binPath), nil
2633
}
2734

2835
func getFilePath(name string) (string, error) {
@@ -80,6 +87,7 @@ func download(path, url string) error {
8087
if err != nil {
8188
return err
8289
}
90+
logger.InfoMsgf("Downloading from %s", url)
8391
response, err := client.Get(url)
8492
if err != nil {
8593
return err
@@ -99,21 +107,23 @@ func execute(url string) error {
99107
if err != nil {
100108
return err
101109
}
110+
logger.InfoMsgf("Created tmp file %s", path)
102111
defer os.Remove(path)
103112

104113
err = download(path, url)
105114
if err != nil {
106115
return err
107116
}
108117

118+
logger.InfoMsgf("Beginning unarchive")
109119
return archiver.Unarchive(path, "/")
110120
}
111121

112122
func main() {
113123
url := os.Getenv("DUCKTAPE_URL")
114124
if len(os.Args) > 1 {
115125
if os.Args[1] == "-v" {
116-
fmt.Println(version)
126+
fmt.Println(cmd.Version)
117127
return
118128
}
119129
url = os.Args[1]

0 commit comments

Comments
 (0)