diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42ebced..d2d4f8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: - go: [ '1.20.x', '1.21.x' ] + go: [ '1.21.x', '1.22.x' ] steps: - name: Checkout diff --git a/cli/cli.go b/cli/cli.go index f1de2c3..07a9be0 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -15,10 +15,14 @@ import ( "strings" "time" + "github.com/essentialkaos/ek/v12/env" "github.com/essentialkaos/ek/v12/fmtc" "github.com/essentialkaos/ek/v12/fmtutil" "github.com/essentialkaos/ek/v12/options" "github.com/essentialkaos/ek/v12/signal" + "github.com/essentialkaos/ek/v12/support" + "github.com/essentialkaos/ek/v12/support/apps" + "github.com/essentialkaos/ek/v12/support/deps" "github.com/essentialkaos/ek/v12/timeutil" "github.com/essentialkaos/ek/v12/usage" "github.com/essentialkaos/ek/v12/usage/completion/bash" @@ -27,7 +31,6 @@ import ( "github.com/essentialkaos/ek/v12/usage/man" "github.com/essentialkaos/ek/v12/usage/update" - "github.com/essentialkaos/fz/cli/support" "github.com/essentialkaos/fz/gofuzz" ) @@ -36,7 +39,7 @@ import ( // App info const ( APP = "fz" - VER = "1.1.1" + VER = "1.1.2" DESC = "Tool for formatting go-fuzz output" ) @@ -97,7 +100,12 @@ func Run(gitRev string, gomod []byte) { genAbout(gitRev).Print(options.GetS(OPT_VER)) os.Exit(0) case options.GetB(OPT_VERB_VER): - support.Print(APP, VER, gitRev, gomod) + support.Collect(APP, VER). + WithRevision(gitRev). + WithDeps(deps.Extract(gomod)). + WithApps(apps.Golang()). + WithChecks(checkForGoFuzz()). + Print() os.Exit(0) case options.GetB(OPT_HELP) || !hasStdinData(): genUsage().Print() @@ -254,6 +262,17 @@ func printError(f string, a ...any) { // ////////////////////////////////////////////////////////////////////////////////// // +// checkForGoFuzz checks if go-fuzz binary present on the system +func checkForGoFuzz() support.Check { + goFuzzBin := env.Which("go-fuzz") + + if goFuzzBin == "" { + return support.Check{support.CHECK_ERROR, "go-fuzz", "Binary not found in PATH"} + } + + return support.Check{support.CHECK_OK, "go-fuzz", fmt.Sprintf("Binary found (%s)", goFuzzBin)} +} + // printCompletion prints completion for given shell func printCompletion() int { switch options.GetS(OPT_COMPLETION) { @@ -309,12 +328,15 @@ func genAbout(gitRev string) *usage.About { VersionColorTag: colorTagVer, DescSeparator: "{s}—{!}", - License: "Apache License, Version 2.0 ", - UpdateChecker: usage.UpdateChecker{"essentialkaos/fz", update.GitHubChecker}, + License: "Apache License, Version 2.0 ", } if gitRev != "" { about.Build = "git:" + gitRev + about.UpdateChecker = usage.UpdateChecker{ + "essentialkaos/fz", + update.GitHubChecker, + } } return about diff --git a/cli/support/support.go b/cli/support/support.go deleted file mode 100644 index 31dc9c0..0000000 --- a/cli/support/support.go +++ /dev/null @@ -1,162 +0,0 @@ -package support - -// ////////////////////////////////////////////////////////////////////////////////// // -// // -// Copyright (c) 2024 ESSENTIAL KAOS // -// Apache License, Version 2.0 // -// // -// ////////////////////////////////////////////////////////////////////////////////// // - -import ( - "fmt" - "os" - "os/exec" - "runtime" - "runtime/debug" - "strings" - - "github.com/essentialkaos/ek/v12/fmtc" - "github.com/essentialkaos/ek/v12/fmtutil" - "github.com/essentialkaos/ek/v12/hash" - "github.com/essentialkaos/ek/v12/strutil" - - "github.com/essentialkaos/depsy" -) - -// ////////////////////////////////////////////////////////////////////////////////// // - -// Print prints verbose info about application, system, dependencies and -// important environment -func Print(app, ver, gitRev string, gomod []byte) { - fmtutil.SeparatorTitleColorTag = "{s-}" - fmtutil.SeparatorFullscreen = false - fmtutil.SeparatorColorTag = "{s-}" - fmtutil.SeparatorSize = 80 - - showApplicationInfo(app, ver, gitRev) - showOSInfo() - showEnvInfo() - showDepsInfo(gomod) - - fmtutil.Separator(false) -} - -// ////////////////////////////////////////////////////////////////////////////////// // - -// showApplicationInfo shows verbose information about application -func showApplicationInfo(app, ver, gitRev string) { - fmtutil.Separator(false, "APPLICATION INFO") - - printInfo(7, "Name", app) - printInfo(7, "Version", ver) - - printInfo(7, "Go", fmtc.Sprintf( - "%s {s}(%s/%s){!}", - strings.TrimLeft(runtime.Version(), "go"), - runtime.GOOS, runtime.GOARCH, - )) - - if gitRev == "" { - gitRev = extractGitRevFromBuildInfo() - } - - if gitRev != "" { - if !fmtc.DisableColors && fmtc.IsTrueColorSupported() { - printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev)) - } else { - printInfo(7, "Git SHA", gitRev) - } - } - - bin, _ := os.Executable() - binSHA := hash.FileHash(bin) - - if binSHA != "" { - binSHA = strutil.Head(binSHA, 7) - if !fmtc.DisableColors && fmtc.IsTrueColorSupported() { - printInfo(7, "Bin SHA", binSHA+getHashColorBullet(binSHA)) - } else { - printInfo(7, "Bin SHA", binSHA) - } - } -} - -// showEnvInfo shows info about environment -func showEnvInfo() { - fmtutil.Separator(false, "ENVIRONMENT") - - cmd := exec.Command("go", "version") - out, err := cmd.Output() - - if err != nil { - printInfo(2, "Go", "") - return - } - - goVer := string(out) - goVer = strutil.ReadField(goVer, 2, false, " ") - goVer = strutil.Exclude(goVer, "go") - - printInfo(2, "Go", goVer) -} - -// showDepsInfo shows information about all dependencies -func showDepsInfo(gomod []byte) { - deps := depsy.Extract(gomod, false) - - if len(deps) == 0 { - return - } - - fmtutil.Separator(false, "DEPENDENCIES") - - for _, dep := range deps { - if dep.Extra == "" { - fmtc.Printf(" {s}%8s{!} %s\n", dep.Version, dep.Path) - } else { - fmtc.Printf(" {s}%8s{!} %s {s-}(%s){!}\n", dep.Version, dep.Path, dep.Extra) - } - } -} - -// extractGitRevFromBuildInfo extracts git SHA from embedded build info -func extractGitRevFromBuildInfo() string { - info, ok := debug.ReadBuildInfo() - - if !ok { - return "" - } - - for _, s := range info.Settings { - if s.Key == "vcs.revision" && len(s.Value) > 7 { - return s.Value[:7] - } - } - - return "" -} - -// getHashColorBullet return bullet with color from hash -func getHashColorBullet(v string) string { - if len(v) > 6 { - v = strutil.Head(v, 6) - } - - return fmtc.Sprintf(" {#" + strutil.Head(v, 6) + "}● {!}") -} - -// printInfo formats and prints info record -func printInfo(size int, name, value string) { - name += ":" - size++ - - if value == "" { - fm := fmt.Sprintf(" {*}%%-%ds{!} {s-}—{!}\n", size) - fmtc.Printf(fm, name) - } else { - fm := fmt.Sprintf(" {*}%%-%ds{!} %%s\n", size) - fmtc.Printf(fm, name, value) - } -} - -// ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/support/support_darwin.go b/cli/support/support_darwin.go deleted file mode 100644 index 4647acb..0000000 --- a/cli/support/support_darwin.go +++ /dev/null @@ -1,40 +0,0 @@ -package support - -// ////////////////////////////////////////////////////////////////////////////////// // -// // -// Copyright (c) 2024 ESSENTIAL KAOS // -// Apache License, Version 2.0 // -// // -// ////////////////////////////////////////////////////////////////////////////////// // - -import ( - "github.com/essentialkaos/ek/v12/fmtutil" - "github.com/essentialkaos/ek/v12/system" -) - -// ////////////////////////////////////////////////////////////////////////////////// // - -// showOSInfo shows verbose information about system -func showOSInfo() { - systemInfo, err := system.GetSystemInfo() - - if err != nil { - return - } - - osInfo, err := system.GetOSInfo() - - if err == nil { - fmtutil.Separator(false, "OS INFO") - - printInfo(12, "Name", osInfo.Name) - printInfo(12, "Version", osInfo.VersionID) - printInfo(12, "Build", osInfo.Build) - } - - fmtutil.Separator(false, "SYSTEM INFO") - - printInfo(7, "Name", systemInfo.OS) - printInfo(7, "Arch", systemInfo.Arch) - printInfo(7, "Kernel", systemInfo.Kernel) -} diff --git a/cli/support/support_linux.go b/cli/support/support_linux.go deleted file mode 100644 index e1f5719..0000000 --- a/cli/support/support_linux.go +++ /dev/null @@ -1,63 +0,0 @@ -package support - -// ////////////////////////////////////////////////////////////////////////////////// // -// // -// Copyright (c) 2024 ESSENTIAL KAOS // -// Apache License, Version 2.0 // -// // -// ////////////////////////////////////////////////////////////////////////////////// // - -import ( - "github.com/essentialkaos/ek/v12/fmtc" - "github.com/essentialkaos/ek/v12/fmtutil" - "github.com/essentialkaos/ek/v12/system" - "github.com/essentialkaos/ek/v12/system/container" -) - -// ////////////////////////////////////////////////////////////////////////////////// // - -// showOSInfo shows verbose information about system -func showOSInfo() { - osInfo, err := system.GetOSInfo() - - if err == nil { - fmtutil.Separator(false, "OS INFO") - - printInfo(12, "Name", osInfo.ColoredName()) - printInfo(12, "Pretty Name", osInfo.ColoredPrettyName()) - printInfo(12, "Version", osInfo.Version) - printInfo(12, "ID", osInfo.ID) - printInfo(12, "ID Like", osInfo.IDLike) - printInfo(12, "Version ID", osInfo.VersionID) - printInfo(12, "Version Code", osInfo.VersionCodename) - printInfo(12, "Platform ID", osInfo.PlatformID) - printInfo(12, "CPE", osInfo.CPEName) - } - - systemInfo, err := system.GetSystemInfo() - - if err != nil { - return - } else if osInfo == nil { - fmtutil.Separator(false, "SYSTEM INFO") - printInfo(12, "Name", systemInfo.OS) - } - - printInfo(12, "Arch", systemInfo.Arch) - printInfo(12, "Kernel", systemInfo.Kernel) - - containerEngine := "No" - - switch container.GetEngine() { - case container.DOCKER: - containerEngine = "Yes (Docker)" - case container.PODMAN: - containerEngine = "Yes (Podman)" - case container.LXC: - containerEngine = "Yes (LXC)" - } - - fmtc.NewLine() - - printInfo(12, "Container", containerEngine) -} diff --git a/go.mod b/go.mod index b1c72da..47c922b 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,13 @@ go 1.18 require ( github.com/essentialkaos/check v1.4.0 - github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.93.0 + github.com/essentialkaos/ek/v12 v12.113.1 ) require ( + github.com/essentialkaos/depsy v1.1.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/sys v0.18.0 // indirect ) diff --git a/go.sum b/go.sum index eaaef22..84c3e67 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1n github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0= github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI= github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.93.0 h1:5lwuNYgUYjQHy2h57adWt2t1w5L2MxqTPKgHjyH3h6k= -github.com/essentialkaos/ek/v12 v12.93.0/go.mod h1:peB5w8zUkRuDs7m/QG5Z2gMmqzSIs2viAmxzzNFIIoo= +github.com/essentialkaos/ek/v12 v12.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg= +github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -13,5 +13,5 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/gofuzz/gofuzz.go b/gofuzz/gofuzz.go index 7ebe7da..0d90fb6 100644 --- a/gofuzz/gofuzz.go +++ b/gofuzz/gofuzz.go @@ -48,8 +48,8 @@ func Parse(line string) (Line, error) { data[4] = strutil.Exclude(data[4], "(") data[4] = strutil.Exclude(data[4], ")") - dateTime := strutil.ReadField(data[0], 0, false, " ") + " " - dateTime += strutil.ReadField(data[0], 1, false, " ") + dateTime := strutil.ReadField(data[0], 0, false, ' ') + " " + dateTime += strutil.ReadField(data[0], 1, false, ' ') result.DateTime, err = time.Parse("2006/01/02 15:04:05", dateTime) @@ -57,43 +57,43 @@ func Parse(line string) (Line, error) { return Line{}, fmt.Errorf("Can't parse date and time field: %w", err) } - result.Workers, err = strconv.Atoi(strutil.ReadField(data[0], 3, false, " ")) + result.Workers, err = strconv.Atoi(strutil.ReadField(data[0], 3, false, ' ')) if err != nil { return Line{}, fmt.Errorf("Can't parse workers field: %w", err) } - result.Corpus, err = strconv.Atoi(strutil.ReadField(data[1], 1, false, " ")) + result.Corpus, err = strconv.Atoi(strutil.ReadField(data[1], 1, false, ' ')) if err != nil { return Line{}, fmt.Errorf("Can't parse corpus field: %w", err) } - result.Crashers, err = strconv.Atoi(strutil.ReadField(data[2], 1, false, " ")) + result.Crashers, err = strconv.Atoi(strutil.ReadField(data[2], 1, false, ' ')) if err != nil { return Line{}, fmt.Errorf("Can't parse crashers field: %w", err) } - result.Restarts, err = strconv.Atoi(strutil.ReadField(data[3], 1, false, " ")) + result.Restarts, err = strconv.Atoi(strutil.ReadField(data[3], 1, false, ' ')) if err != nil { return Line{}, fmt.Errorf("Can't parse restarts field: %w", err) } - result.Execs, err = strconv.Atoi(strutil.ReadField(data[4], 1, false, " ")) + result.Execs, err = strconv.Atoi(strutil.ReadField(data[4], 1, false, ' ')) if err != nil { return Line{}, fmt.Errorf("Can't parse execs field: %w", err) } - result.ExecsPerSec, err = strconv.Atoi(strutil.ReadField(data[4], 2, false, " ")) + result.ExecsPerSec, err = strconv.Atoi(strutil.ReadField(data[4], 2, false, ' ')) if err != nil { return Line{}, fmt.Errorf("Can't parse execs per sec field: %w", err) } - result.Cover, err = strconv.Atoi(strutil.ReadField(data[5], 1, false, " ")) + result.Cover, err = strconv.Atoi(strutil.ReadField(data[5], 1, false, ' ')) if err != nil { return Line{}, fmt.Errorf("Can't parse cover field: %w", err)