Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ linters:
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# Exclude some linters from testing files.
- linters:
- forbidigo
- lll
path: 'init/config/.*.\.go'

output:
sort-results: true
run:
Expand Down
3 changes: 2 additions & 1 deletion init/config/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
generated
docker-compose.yml
unpackerr.conf.example
unpackerr.conf.example
config
4 changes: 2 additions & 2 deletions init/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and a suite of docusaurus-markdown files to create the official

The config file is generated every time `go generate` runs. This happens during the build, so the
config file compiled into the application is always up to date. The repo needs to be updated manually
when the definition file changes. Just run `go generate` before committing.
when the definition file changes. Just run `go generate ./...` before committing.

### Compose Service

Expand Down Expand Up @@ -78,4 +78,4 @@ The data that follows describes all the parameters for that section.

## Sections

_(write more here about the sections layout)_
_(write more here about the sections layout)_
4 changes: 3 additions & 1 deletion init/config/compose-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
)

//nolint:lll
const (
space = " "
composeHeader = `### Unpackerr docker-compose.yml Example
Expand Down Expand Up @@ -49,7 +50,8 @@ func createCompose(config *Config, output string) {
if config.Defs[section] == nil {
buf.WriteString(config.Sections[section].makeCompose(config.Prefix, false))
} else {
buf.WriteString(config.Sections[section].makeComposeDefined(config.Prefix, config.Defs[section], config.DefOrder[section], false))
buf.WriteString(config.Sections[section].
makeComposeDefined(config.Prefix, config.Defs[section], config.DefOrder[section], false))
}
}

Expand Down
5 changes: 3 additions & 2 deletions init/config/docs-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func writeDocusaurus(dir, file, content string) error {
_ = os.Mkdir(dir, dirMode)
date := "---\n# Generated: " + time.Now().Round(time.Second).String() + "\n---\n\n"
filePath := filepath.Join(dir, file+".md")
fmt.Printf("Writing: %s, size: %d\n", filePath, len(content))
log.Printf("Writing: %s, size: %d", filePath, len(content))
//nolint:wrapcheck
return os.WriteFile(filePath, []byte(date+content), fileMode)
}
Expand Down Expand Up @@ -86,7 +86,8 @@ func (h *Header) makeDocs(prefix string, section section) string {
if h.NoHeader {
buf.WriteString(" <summary>Examples. Prefix: <b>" + prefix + "</b></summary>\n\n")
} else {
buf.WriteString(" <summary>Examples. Prefix: <b>" + prefix + h.Prefix + "</b>, Header: <b>" + header + "</b></summary>\n\n")
buf.WriteString(" <summary>Examples. Prefix: <b>" + prefix + h.Prefix +
"</b>, Header: <b>" + header + "</b></summary>\n\n")
}

buf.WriteString("- Using the config file:\n\n```yaml\n")
Expand Down
36 changes: 26 additions & 10 deletions init/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package main

import (
"bytes"
_ "embed"
"fmt"
"io"
"log"
Expand All @@ -22,10 +24,12 @@ const (
outputDir = "generated/"
exampleConfig = "unpackerr.conf.example"
exampleCompose = "docker-compose.yml"
inputFile = "https://raw.githubusercontent.com/Unpackerr/unpackerr/main/init/config/conf-builder.yml"
opTimeout = 6 * time.Second
)

//go:embed conf-builder.yml
var confBuilder []byte

type section string

type Option struct {
Expand Down Expand Up @@ -91,13 +95,13 @@ func main() {

for _, builder := range flags.Type {
switch builder {
case "docs":
case "doc", "docs", "documentation", "docusaurus":
log.Println("Building Docusaurus")
printDocusaurus(config, flags.Docs)
case "config":
case "conf", "config":
log.Println("Building Config File")
printConfFile(config, flags.Config)
case "compose":
case "docker", "compose", "yml":
log.Println("Building Docker Compose")
createCompose(config, flags.Compose)
}
Expand All @@ -114,18 +118,30 @@ type flags struct {

func parseFlags() *flags {
flags := flags{}
flag.StringSliceVarP(&flags.Type, "type", "t", []string{"compose", "docs", "config"}, "Choose 1 or more outputs, or don't and get them all.")
flag.StringVar(&flags.Config, "config", exampleConfig, "Choose filename for generated config file.")
flag.StringVar(&flags.Compose, "compose", exampleCompose, "Choose a filename for the generated docker compose service.")
flag.StringVar(&flags.Docs, "docs", outputDir, "Choose folder for generated documentation. ")
flag.StringVarP(&flags.File, "file", "f", inputFile, "URL or filepath for conf-builder.yml")
flag.StringSliceVarP(&flags.Type, "type", "t", []string{"compose", "docs", "config"},
"Choose 1 or more outputs, or don't and get them all.")
flag.StringVar(&flags.Config, "config", exampleConfig,
"Choose filename for generated config file.")
flag.StringVar(&flags.Compose, "compose", exampleCompose,
"Choose a filename for the generated docker compose service.")
flag.StringVar(&flags.Docs, "docs", outputDir,
"Choose folder for generated documentation. ")
flag.StringVarP(&flags.File, "file", "f", "internal",
"URL or filepath for conf-builder.yml, internal uses the compiled-in file")
flag.Parse()

return &flags
}

// openFile opens a file or url for the parser.
// openFile opens a file or url for the parser, or returns the internal file.
func openFile(fileName string) (io.ReadCloser, error) {
if fileName == "internal" {
buf := bytes.Buffer{}
buf.Write(confBuilder)

return io.NopCloser(&buf), nil
}

if strings.HasPrefix(fileName, "http") {
http.DefaultClient.Timeout = opTimeout

Expand Down