Skip to content

Commit

Permalink
e-a-s-y
Browse files Browse the repository at this point in the history
  • Loading branch information
dazz committed Dec 29, 2023
1 parent 002d35a commit 848095e
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 187 deletions.
29 changes: 8 additions & 21 deletions cmd/s6cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/dazz/s6-cli/internal/domain/lint"
"github.com/dazz/s6-cli/internal/domain/mermaid"
"github.com/dazz/s6-cli/internal/infrastructure/persistence"
"log"
"os"
Expand All @@ -13,10 +14,8 @@ import (
"github.com/dazz/s6-cli/pkg/s6cli"
)

func init() {
}

func main() {
rootPath := "/etc/s6-overlay/s6-rc.d"
app := &cli.App{
Name: "s6-cli",
Version: "0.0.1",
Expand Down Expand Up @@ -44,16 +43,14 @@ func main() {
Aliases: []string{"l"},
Usage: "lint directories and files",
Action: func(cCtx *cli.Context) error {
rootPath := "/etc/s6-overlay/s6-rc.d"

if cCtx.IsSet("rootPath") {
rootPath = cCtx.String("rootPath")
}

repo := persistence.NewFilesystem(rootPath)
action := lint.NewAction(repo)

fmt.Println(action.Lint())
fmt.Println(action.Output())

return nil
},
Expand All @@ -63,24 +60,14 @@ func main() {
Aliases: []string{"m"},
Usage: "document s6 service dependencies in mermaid syntax",
Action: func(cCtx *cli.Context) error {
path := "/etc/s6-overlay/s6-rc.d"
firstBundle := "user"

if cCtx.IsSet("path") {
path = cCtx.String("path")
}
// check if the directory exists
if _, err := os.Stat(path); os.IsNotExist(err) {
fmt.Printf("Directory %s does not exist\n", path)
os.Exit(1)
if cCtx.IsSet("rootPath") {
rootPath = cCtx.String("rootPath")
}

// compile dependency tree
var services []s6cli.Service
var lints []s6cli.Lint
s6cli.Compile(path, firstBundle, &services, &lints)
repo := persistence.NewFilesystem(rootPath)
action := mermaid.NewAction(repo)

fmt.Printf(s6cli.MermaidGraph(services))
fmt.Println(action.Output())

return nil
},
Expand Down
2 changes: 1 addition & 1 deletion internal/domain/lint/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewAction(repository service.Repository) *Action {
}
}

func (a *Action) Lint() string {
func (a *Action) Output() string {
// do all the fun stuff here
services, err := a.repository.All()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/domain/lint/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
)

func TestAction_Lint(t *testing.T) {
t.Run("Lint() returns string", func(t *testing.T) {
t.Run("Output() returns string", func(t *testing.T) {
repo := &mock.Repository{}
action := NewAction(repo)
result := action.Lint()
result := action.Output()

if result == "" {
t.Errorf("Lint() must return a string")
t.Errorf("Output() must return a string")
}
})
}
37 changes: 37 additions & 0 deletions internal/domain/mermaid/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package mermaid

import (
"fmt"
"github.com/dazz/s6-cli/internal/domain/service"
"log"
"strings"
)

type Action struct {
repository service.Repository
}

func NewAction(repository service.Repository) *Action {
return &Action{
repository: repository,
}
}

func (a *Action) Output() string {
// do all the fun stuff hereLint
services, err := a.repository.All()
if err != nil {
log.Println(err)
}

var output []string
output = append(output, "```mermaid")
output = append(output, "graph TD;")
for _, s := range services {
for _, dependency := range s.Dependencies {
output = append(output, fmt.Sprintf(" %s --> %s", s.Id, dependency))
}
}
output = append(output, "```")
return strings.Join(output, "\n")
}
18 changes: 18 additions & 0 deletions internal/domain/mermaid/action_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mermaid

import (
"github.com/dazz/s6-cli/internal/infrastructure/persistence/mock"
"testing"
)

func TestAction_Lint(t *testing.T) {
t.Run("Output() returns string", func(t *testing.T) {
repo := &mock.Repository{}
action := NewAction(repo)
result := action.Output()

if result == "" {
t.Errorf("Output() must return a string")
}
})
}
161 changes: 0 additions & 161 deletions pkg/s6cli/lint.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/s6cli/mermaid.go

This file was deleted.

0 comments on commit 848095e

Please sign in to comment.