diff --git a/Makefile b/Makefile index 77c921f..66b296f 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,14 @@ dep: ## build: build binary file .PHONY: build build: - @GOARCH=amd64 GOOS=linux go build -o ${BINARY_NAME} -v ./cmd/s6cli + @GOARCH=amd64 GOOS=linux go build -o /Users/dazz/bin/${BINARY_NAME} -v ./cmd/s6cli + +## build: build binary file +.PHONY: build-darwin +build-darwin: + @GOARCH=amd64 GOOS=darwin go build -o ${BINARY_NAME} -v ./cmd/s6cli + + ## clean: clean binary file .PHONY: clean @@ -60,7 +67,7 @@ run: ## test: run all tests .PHONY: test test: - @go test -v ./... + @go test ./... ## test-coverage: run all tests with coverage .PHONY: test-coverage diff --git a/README.md b/README.md index f53ec63..b6867a5 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ All commands need the `rootPath` to be specified. It must point to the directory Default is set to `/etc/s6-overlay/s6-rc.d` ### Create -There are three types of services that can be created: Oneshot, Longrun and Background. +There are three types of services that can be created: Oneshot, Longrun and Bundle. Read more about them [here](https://skarnet.org/software/s6-rc/s6-rc-compile.html) ```bash diff --git a/cmd/s6cli/main.go b/cmd/s6cli/main.go index 215755f..b46294b 100644 --- a/cmd/s6cli/main.go +++ b/cmd/s6cli/main.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/dazz/s6-cli/internal/domain/create" "github.com/dazz/s6-cli/internal/domain/lint" @@ -53,10 +54,13 @@ func main() { execute, err := command.Execute() if err != nil { - fmt.Println(err) + return err } - fmt.Println(execute) - + if execute != "" { + fmt.Println("s6-cli: lint found issues with services in " + rootPath) + return errors.New(execute) + } + fmt.Println("s6-cli: lint found no issues") return nil }, }, @@ -78,7 +82,6 @@ func main() { } fmt.Println(execute) - return nil }, }, @@ -95,11 +98,6 @@ func main() { if cCtx.IsSet("rootPath") { rootPath = cCtx.String("rootPath") } - // check if the directory exists - if _, err := os.Stat(rootPath); os.IsNotExist(err) { - fmt.Printf("Directory %s does not exist\n", rootPath) - os.Exit(1) - } var serviceType service.Type switch t := cCtx.Args().Get(0); t { @@ -129,11 +127,9 @@ func main() { result, err := command.Execute() if err != nil { - fmt.Println(err) - os.Exit(1) + return err } fmt.Printf("Successful created service %q\n", result) - return nil }, }, @@ -147,18 +143,12 @@ func main() { if cCtx.IsSet("rootPath") { rootPath = cCtx.String("rootPath") } - // check if the directory exists - if _, err := os.Stat(rootPath); os.IsNotExist(err) { - fmt.Println("Directory does not exist: " + rootPath) - os.Exit(1) - } var id service.Id if idArg := cCtx.Args().Get(0); idArg != "" { id = service.Id(idArg) } else { - fmt.Println("Arg idArg must not be empty") - os.Exit(1) + return errors.New("arg idArg must not be empty") } repo := filesystem.NewFilesystem(rootPath) @@ -166,8 +156,7 @@ func main() { result, err := command.Execute() if err != nil { - fmt.Println(err) - os.Exit(1) + return err } fmt.Printf("Successful removed service %q\n", result) return nil diff --git a/internal/infrastructure/persistence/filesystem/repository.go b/internal/infrastructure/persistence/filesystem/repository.go index 0823f54..b2dff2e 100644 --- a/internal/infrastructure/persistence/filesystem/repository.go +++ b/internal/infrastructure/persistence/filesystem/repository.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/dazz/s6-cli/internal/domain/service" + "log" "os" "path/filepath" "strings" @@ -19,7 +20,10 @@ type Filesystem struct { func NewFilesystem(rootPath string) *Filesystem { - // TODO: check if rootPath is valid + // check if the directory exists + if _, err := os.Stat(rootPath); os.IsNotExist(err) { + log.Fatal("rootPath directory does not exist: " + rootPath) + } return &Filesystem{ rootPath: rootPath,