User-Friendliness

This commit is contained in:
2026-04-02 20:41:48 +02:00
parent af4d23ea48
commit 7c7eb4dcc0
2 changed files with 74 additions and 10 deletions
+39 -9
View File
@@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strings"
"gitea.westgate.pw/ShadowsOverWestgate/sow-tools/internal/pipeline"
@@ -133,7 +134,9 @@ func runBuildModule(ctx context) error {
return err
}
result, err := pipeline.BuildModule(p)
result, err := pipeline.BuildModuleWithProgress(p, func(message string) {
fmt.Fprintf(ctx.stdout, "[build-module] %s\n", message)
})
if err != nil {
return err
}
@@ -150,7 +153,9 @@ func runBuildHAKs(ctx context) error {
return err
}
result, err := pipeline.BuildHAKs(p)
result, err := pipeline.BuildHAKsWithProgress(p, func(message string) {
fmt.Fprintf(ctx.stdout, "[build-haks] %s\n", message)
})
if err != nil {
return err
}
@@ -195,10 +200,9 @@ func runValidate(ctx context) error {
validationReport := validator.ValidateProject(p)
if validationReport.HasErrors() {
emitValidationWarnings(ctx.stderr, validationReport.Diagnostics)
for _, diagnostic := range validationReport.Diagnostics {
if diagnostic.Severity == validator.SeverityWarning {
fprintfTarget := ctx.stderr
fmt.Fprintf(fprintfTarget, "warning: %s: %s\n", diagnostic.Path, diagnostic.Message)
continue
}
fmt.Fprintf(ctx.stderr, "error: %s: %s\n", diagnostic.Path, diagnostic.Message)
@@ -206,11 +210,7 @@ func runValidate(ctx context) error {
return fmt.Errorf("validation failed with %d error(s)", validationReport.ErrorCount())
}
for _, diagnostic := range validationReport.Diagnostics {
if diagnostic.Severity == validator.SeverityWarning {
fmt.Fprintf(ctx.stderr, "warning: %s: %s\n", diagnostic.Path, diagnostic.Message)
}
}
emitValidationWarnings(ctx.stderr, validationReport.Diagnostics)
inventoryReport := p.Inventory.Report()
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
@@ -226,6 +226,36 @@ func runValidate(ctx context) error {
return nil
}
func emitValidationWarnings(w io.Writer, diagnostics []validator.Diagnostic) {
const lowercaseWarning = "resource filenames should be lowercase"
lowercasePaths := make([]string, 0)
for _, diagnostic := range diagnostics {
if diagnostic.Severity != validator.SeverityWarning {
continue
}
if diagnostic.Message == lowercaseWarning {
lowercasePaths = append(lowercasePaths, diagnostic.Path)
continue
}
fmt.Fprintf(w, "warning: %s: %s\n", diagnostic.Path, diagnostic.Message)
}
if len(lowercasePaths) == 0 {
return
}
slices.Sort(lowercasePaths)
examples := lowercasePaths
if len(examples) > 5 {
examples = examples[:5]
}
message := strings.Join(examples, ", ")
if len(lowercasePaths) > len(examples) {
message += fmt.Sprintf(", and %d more", len(lowercasePaths)-len(examples))
}
fmt.Fprintf(w, "warning: %d resource filenames are not lowercase: %s\n", len(lowercasePaths), message)
}
func runCompare(ctx context) error {
p, err := loadProject(ctx.cwd)
if err != nil {