-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
123 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
S6_PATH := ./data/s6-overlay/s6-rc.d | ||
S6_PATH := ./examples/s6-overlay/s6-rc.d | ||
ARGS := -p $(S6_PATH) | ||
|
||
.PHONY: build | ||
build: | ||
go build -o s6-cli -v ./cmd/s6-cli | ||
@go build -o s6-cli -v ./cmd/s6cli | ||
|
||
.PHONY: run | ||
run: | ||
go run ./cmd/s6-cli $(ARGS) | ||
@go run ./cmd/s6cli $(ARGS) | ||
|
||
.PHONY: lint | ||
lint: | ||
go run ./cmd/s6-cli $(ARGS) lint | ||
@go run ./cmd/s6cli $(ARGS) lint | ||
|
||
.PHONY: mermaid | ||
mermaid: | ||
go run ./cmd/s6-cli $(ARGS) mermaid | ||
@go run ./cmd/s6cli $(ARGS) mermaid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/dazz/s6-cli/pkg/s6cli" | ||
) | ||
|
||
func init() { | ||
} | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "s6-cli", | ||
Version: "0.0.1", | ||
Compiled: time.Now(), | ||
Authors: []*cli.Author{ | ||
&cli.Author{ | ||
Name: "Anne-Julia Seitz", | ||
Email: "dazz@c-base", | ||
}, | ||
}, | ||
Usage: "CLI for creating and linting files and directories", | ||
// We'll be using the same flag for all our commands | ||
// so we'll define it up here | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "path", | ||
Aliases: []string{"p"}, | ||
Value: "/etc/s6-overlay/s6-rc.d", | ||
Usage: "Path to s6-rc.d directory", | ||
}, | ||
}, | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "lint", | ||
Aliases: []string{"l"}, | ||
Usage: "lint directories and files", | ||
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) | ||
} | ||
|
||
// compile dependency tree | ||
var services []s6cli.Service | ||
var lints []s6cli.Lint | ||
valid := s6cli.Compile(path, firstBundle, &services, &lints) | ||
|
||
fmt.Println("*************** s6-cli Lint Report ***************") | ||
|
||
// print lints | ||
for _, lint := range lints { | ||
fmt.Printf("* %s: %s\n", lint.Service, lint.Message) | ||
} | ||
|
||
fmt.Println("*************** s6-cli Lint Report ***************") | ||
|
||
if valid { | ||
return nil | ||
} | ||
os.Exit(1) | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "mermaid", | ||
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) | ||
} | ||
|
||
// compile dependency tree | ||
var services []s6cli.Service | ||
var lints []s6cli.Lint | ||
s6cli.Compile(path, firstBundle, &services, &lints) | ||
|
||
fmt.Printf(s6cli.MermaidGraph(services)) | ||
|
||
return nil | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
if err := app.Run(os.Args); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters