Skip to content

Commit 260b2be

Browse files
committed
update error messages
1 parent 3b97c48 commit 260b2be

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ dep:
4444
## build: build binary file
4545
.PHONY: build
4646
build:
47-
@GOARCH=amd64 GOOS=linux go build -o ${BINARY_NAME} -v ./cmd/s6cli
47+
@GOARCH=amd64 GOOS=linux go build -o /Users/dazz/bin/${BINARY_NAME} -v ./cmd/s6cli
48+
49+
## build: build binary file
50+
.PHONY: build-darwin
51+
build-darwin:
52+
@GOARCH=amd64 GOOS=darwin go build -o ${BINARY_NAME} -v ./cmd/s6cli
53+
54+
4855

4956
## clean: clean binary file
5057
.PHONY: clean
@@ -60,7 +67,7 @@ run:
6067
## test: run all tests
6168
.PHONY: test
6269
test:
63-
@go test -v ./...
70+
@go test ./...
6471

6572
## test-coverage: run all tests with coverage
6673
.PHONY: test-coverage

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ All commands need the `rootPath` to be specified. It must point to the directory
5555
Default is set to `/etc/s6-overlay/s6-rc.d`
5656

5757
### Create
58-
There are three types of services that can be created: Oneshot, Longrun and Background.
58+
There are three types of services that can be created: Oneshot, Longrun and Bundle.
5959
Read more about them [here](https://skarnet.org/software/s6-rc/s6-rc-compile.html)
6060

6161
```bash

cmd/s6cli/main.go

+10-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"github.com/dazz/s6-cli/internal/domain/create"
67
"github.com/dazz/s6-cli/internal/domain/lint"
@@ -53,10 +54,13 @@ func main() {
5354

5455
execute, err := command.Execute()
5556
if err != nil {
56-
fmt.Println(err)
57+
return err
5758
}
58-
fmt.Println(execute)
59-
59+
if execute != "" {
60+
fmt.Println("s6-cli: lint found issues with services in " + rootPath)
61+
return errors.New(execute)
62+
}
63+
fmt.Println("s6-cli: lint found no issues")
6064
return nil
6165
},
6266
},
@@ -78,7 +82,6 @@ func main() {
7882
}
7983

8084
fmt.Println(execute)
81-
8285
return nil
8386
},
8487
},
@@ -95,11 +98,6 @@ func main() {
9598
if cCtx.IsSet("rootPath") {
9699
rootPath = cCtx.String("rootPath")
97100
}
98-
// check if the directory exists
99-
if _, err := os.Stat(rootPath); os.IsNotExist(err) {
100-
fmt.Printf("Directory %s does not exist\n", rootPath)
101-
os.Exit(1)
102-
}
103101

104102
var serviceType service.Type
105103
switch t := cCtx.Args().Get(0); t {
@@ -129,11 +127,9 @@ func main() {
129127

130128
result, err := command.Execute()
131129
if err != nil {
132-
fmt.Println(err)
133-
os.Exit(1)
130+
return err
134131
}
135132
fmt.Printf("Successful created service %q\n", result)
136-
137133
return nil
138134
},
139135
},
@@ -147,27 +143,20 @@ func main() {
147143
if cCtx.IsSet("rootPath") {
148144
rootPath = cCtx.String("rootPath")
149145
}
150-
// check if the directory exists
151-
if _, err := os.Stat(rootPath); os.IsNotExist(err) {
152-
fmt.Println("Directory does not exist: " + rootPath)
153-
os.Exit(1)
154-
}
155146

156147
var id service.Id
157148
if idArg := cCtx.Args().Get(0); idArg != "" {
158149
id = service.Id(idArg)
159150
} else {
160-
fmt.Println("Arg idArg must not be empty")
161-
os.Exit(1)
151+
return errors.New("arg idArg must not be empty")
162152
}
163153

164154
repo := filesystem.NewFilesystem(rootPath)
165155
command := remove.NewCommand(repo, id)
166156

167157
result, err := command.Execute()
168158
if err != nil {
169-
fmt.Println(err)
170-
os.Exit(1)
159+
return err
171160
}
172161
fmt.Printf("Successful removed service %q\n", result)
173162
return nil

internal/infrastructure/persistence/filesystem/repository.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"github.com/dazz/s6-cli/internal/domain/service"
7+
"log"
78
"os"
89
"path/filepath"
910
"strings"
@@ -19,7 +20,10 @@ type Filesystem struct {
1920

2021
func NewFilesystem(rootPath string) *Filesystem {
2122

22-
// TODO: check if rootPath is valid
23+
// check if the directory exists
24+
if _, err := os.Stat(rootPath); os.IsNotExist(err) {
25+
log.Fatal("rootPath directory does not exist: " + rootPath)
26+
}
2327

2428
return &Filesystem{
2529
rootPath: rootPath,

0 commit comments

Comments
 (0)