-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move finding table printing to CLI
Signed-off-by: Philip Laine <philip.laine@gmail.com>
- Loading branch information
1 parent
e239857
commit 73cf9de
Showing
9 changed files
with
110 additions
and
148 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/defenseunicorns/pkg/helpers/v2" | ||
"github.com/fatih/color" | ||
|
||
"github.com/zarf-dev/zarf/src/pkg/lint" | ||
"github.com/zarf-dev/zarf/src/pkg/message" | ||
) | ||
|
||
func PrintFindings(lintErr *lint.LintError) { | ||
mapOfFindingsByPath := lint.GroupFindingsByPath(lintErr.Findings, lintErr.PackageName) | ||
for _, findings := range mapOfFindingsByPath { | ||
lintData := [][]string{} | ||
for _, finding := range findings { | ||
sevColor := color.FgWhite | ||
switch finding.Severity { | ||
case lint.SevErr: | ||
sevColor = color.FgRed | ||
case lint.SevWarn: | ||
sevColor = color.FgYellow | ||
} | ||
|
||
lintData = append(lintData, []string{ | ||
colorWrap(string(finding.Severity), sevColor), | ||
colorWrap(finding.YqPath, color.FgCyan), | ||
finding.ItemizedDescription(), | ||
}) | ||
} | ||
var packagePathFromUser string | ||
if helpers.IsOCIURL(findings[0].PackagePathOverride) { | ||
packagePathFromUser = findings[0].PackagePathOverride | ||
} else { | ||
packagePathFromUser = filepath.Join(lintErr.BaseDir, findings[0].PackagePathOverride) | ||
} | ||
message.Notef("Linting package %q at %s", findings[0].PackageNameOverride, packagePathFromUser) | ||
message.Table([]string{"Type", "Path", "Message"}, lintData) | ||
} | ||
} | ||
|
||
func colorWrap(str string, attr color.Attribute) string { | ||
if !message.ColorEnabled() || str == "" { | ||
return str | ||
} | ||
return fmt.Sprintf("\x1b[%dm%s\x1b[0m", attr, str) | ||
} |
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
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
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
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
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
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
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
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