Skip to content

Commit

Permalink
update error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dazz committed Jan 10, 2024
1 parent 3b97c48 commit 260b2be
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 10 additions & 21 deletions cmd/s6cli/main.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
},
},
Expand All @@ -78,7 +82,6 @@ func main() {
}

fmt.Println(execute)

return nil
},
},
Expand All @@ -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 {
Expand Down Expand Up @@ -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
},
},
Expand All @@ -147,27 +143,20 @@ 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)
command := remove.NewCommand(repo, id)

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
Expand Down
6 changes: 5 additions & 1 deletion internal/infrastructure/persistence/filesystem/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/dazz/s6-cli/internal/domain/service"
"log"
"os"
"path/filepath"
"strings"
Expand All @@ -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,
Expand Down

0 comments on commit 260b2be

Please sign in to comment.