Skip to content

Commit

Permalink
Improve checksum output
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Jun 26, 2024
1 parent 9513fab commit 00f494c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 10 additions & 0 deletions action/auxi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

"github.com/essentialkaos/bibop/recipe"
"github.com/essentialkaos/ek/v12/strutil"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -154,6 +155,15 @@ func fmtValue(v string) string {
return v
}

// fmtHash format SHA-256 hash
func fmtHash(v string) string {
if len(v) < 64 {
return v
}

return strutil.Head(v, 7) + "…" + strutil.Tail(v, 7)
}

// sanitizeData removes escape characters
func sanitizeData(data []byte) []byte {
data = bytes.ReplaceAll(data, []byte("\r"), nil)
Expand Down
10 changes: 8 additions & 2 deletions action/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,15 @@ func Checksum(action *recipe.Action) error {

switch {
case !action.Negative && fileHash != mustHash:
return fmt.Errorf("File %s has invalid checksum hash (%s ≠ %s)", file, fileHash, mustHash)
return fmt.Errorf(
"File %s has invalid checksum hash (%s ≠ %s)",
file, fmtHash(fileHash), fmtHash(mustHash),
)
case action.Negative && fileHash == mustHash:
return fmt.Errorf("File %s has invalid checksum hash (%s)", file, fileHash)
return fmt.Errorf(
"File %s has invalid checksum hash (%s)",
file, fmtHash(fileHash),
)
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
// Application info
const (
APP = "bibop"
VER = "8.0.5"
VER = "8.1.0"
DESC = "Utility for testing command-line tools"
)

Expand Down Expand Up @@ -404,11 +404,11 @@ func printCompletion() int {

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Print(bash.Generate(info, "bibop", "recipe"))
fmt.Print(bash.Generate(info, APP, "recipe"))
case "fish":
fmt.Print(fish.Generate(info, "bibop"))
fmt.Print(fish.Generate(info, APP))
case "zsh":
fmt.Print(zsh.Generate(info, optMap, "bibop", "*.recipe"))
fmt.Print(zsh.Generate(info, optMap, APP, "*.recipe"))
default:
return 1
}
Expand Down

0 comments on commit 00f494c

Please sign in to comment.