flags provenance block in index and slices
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package renderer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.flo.fo/FLO/dirmd/internal/config"
|
||||
)
|
||||
|
||||
func FormatFlags(cfg *config.Config) string {
|
||||
if cfg == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var flags []string
|
||||
if cfg.OmitTest {
|
||||
flags = append(flags, "--omit-test")
|
||||
}
|
||||
if cfg.OmitMd {
|
||||
flags = append(flags, "--omit-md")
|
||||
}
|
||||
if cfg.SkipFrontend {
|
||||
flags = append(flags, "--skip-frontend")
|
||||
}
|
||||
if cfg.FrontendOnly {
|
||||
flags = append(flags, "--frontend-only")
|
||||
}
|
||||
if cfg.MaxDepth != config.DefaultMaxDepth {
|
||||
flags = append(flags, fmt.Sprintf("--max-depth %d", cfg.MaxDepth))
|
||||
}
|
||||
if cfg.MaxSize != config.DefaultMaxSize {
|
||||
flags = append(flags, fmt.Sprintf("--max-size %d", cfg.MaxSize))
|
||||
}
|
||||
|
||||
var sb strings.Builder
|
||||
|
||||
if len(flags) > 0 {
|
||||
fmt.Fprintf(&sb, "> Flags: %s\n", strings.Join(flags, " "))
|
||||
}
|
||||
|
||||
extraIgnores := setMinus(cfg.Ignores, config.DefaultIgnores)
|
||||
if len(extraIgnores) > 0 {
|
||||
fmt.Fprintf(&sb, "> Ignored: %s\n", strings.Join(extraIgnores, ", "))
|
||||
}
|
||||
|
||||
var extraExts []string
|
||||
for _, e := range cfg.Extensions {
|
||||
if slices.Contains(config.DefaultExts, e) || slices.Contains(config.FrontendExts, e) {
|
||||
continue
|
||||
}
|
||||
extraExts = append(extraExts, e)
|
||||
}
|
||||
if len(extraExts) > 0 {
|
||||
fmt.Fprintf(&sb, "> Skipped extensions: %s\n", strings.Join(extraExts, ", "))
|
||||
}
|
||||
|
||||
if sb.Len() > 0 {
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func setMinus(haystack, defaults []string) []string {
|
||||
seen := make(map[string]bool)
|
||||
var extra []string
|
||||
for _, h := range haystack {
|
||||
if slices.Contains(defaults, h) || seen[h] {
|
||||
continue
|
||||
}
|
||||
seen[h] = true
|
||||
extra = append(extra, h)
|
||||
}
|
||||
return extra
|
||||
}
|
||||
Reference in New Issue
Block a user