Skip to content

Commit

Permalink
Merge pull request #81 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.1.1
  • Loading branch information
andyone authored Jan 10, 2024
2 parents aca96c5 + 4010af4 commit cba41aa
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 92 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,43 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SRC_DIR: src/github.com/${{ github.repository }}

jobs:
Go:
name: Go
runs-on: ubuntu-latest

strategy:
matrix:
go: [ '1.19.x', '1.20.x' ]
go: [ '1.20.x', '1.21.x' ]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Checkout
uses: actions/checkout@v3
with:
path: ${{env.SRC_DIR}}

- name: Download dependencies
working-directory: ${{env.SRC_DIR}}
run: make deps

- name: Build binary
working-directory: ${{env.SRC_DIR}}
run: make all

- name: Test go-fuzz output parser
working-directory: ${{env.SRC_DIR}}
run: make test

Typos:
name: Typos
runs-on: ubuntu-latest

needs: Go

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check spelling
continue-on-error: true
uses: crate-ci/typos@master
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: go

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fz
vendor
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[files]
extend-exclude = ["go.sum"]
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 2.2.0 using next command:
# This Makefile generated by GoMakeGen 2.3.0 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -13,6 +13,7 @@ ifdef VERBOSE ## Print verbose information (Flag)
VERBOSE_FLAG = -v
endif

COMPAT ?= 1.18
MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)

Expand Down Expand Up @@ -61,7 +62,7 @@ else
endif

ifdef COMPAT ## Compatible Go version (String)
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
else
go mod tidy $(VERBOSE_FLAG)
endif
Expand Down Expand Up @@ -105,6 +106,6 @@ help: ## Show this info
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.2.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 2.3.0\033[0m\n'

################################################################################
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

### Usage demo

[![demo](https://gh.kaos.st/fz-003.gif)](#usage-demo)
[![demo](https://gh.kaos.st/fz-111.gif)](#usage-demo)

### Installation

#### From source

To build the `fz` from scratch, make sure you have a working Go 1.19+ workspace (_[instructions](https://golang.org/doc/install)_), then:
To build the `fz` from scratch, make sure you have a working Go 1.19+ workspace (_[instructions](https://go.dev/doc/install)_), then:

```
go install github.com/essentialkaos/fz@latest
Expand Down Expand Up @@ -68,14 +68,18 @@ fz --generate-man | sudo gzip > /usr/share/man/man1/fz.1.gz
### Usage

```
Usage: go-fuzz … |& fz
Usage: go-fuzz … |& fz {options}
Options
--no-color, -nc Disable colors in output
--help, -h Show this help message
--version, -v Show version
Examples
go-fuzz -bin app-fuzz.zip |& fz
Run fuzz test for app-fuzz.zip
```

### Build Status
Expand Down
56 changes: 36 additions & 20 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -36,7 +36,7 @@ import (
// App info
const (
APP = "fz"
VER = "1.1.0"
VER = "1.1.1"
DESC = "Tool for formatting go-fuzz output"
)

Expand All @@ -56,8 +56,8 @@ const (
// optMap is map with options
var optMap = options.Map{
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL, Alias: "u:usage"},
OPT_VER: {Type: options.BOOL, Alias: "ver"},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

OPT_VERB_VER: {Type: options.BOOL},
OPT_COMPLETION: {},
Expand All @@ -70,6 +70,8 @@ var prev gofuzz.Line
var startTime time.Time
var corpusTime time.Time

var colorTagApp, colorTagVer string

// ////////////////////////////////////////////////////////////////////////////////// //

// Run is main utility function
Expand All @@ -92,10 +94,10 @@ func Run(gitRev string, gomod []byte) {
printMan()
os.Exit(0)
case options.GetB(OPT_VER):
genAbout(gitRev).Print()
genAbout(gitRev).Print(options.GetS(OPT_VER))
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.ShowSupportInfo(APP, VER, gitRev, gomod)
support.Print(APP, VER, gitRev, gomod)
os.Exit(0)
case options.GetB(OPT_HELP) || !hasStdinData():
genUsage().Print()
Expand All @@ -111,6 +113,15 @@ func configureUI() {
if options.GetB(OPT_NO_COLOR) {
fmtc.DisableColors = true
}

switch {
case fmtc.IsTrueColorSupported():
colorTagApp, colorTagVer = "{*}{#00ADD8}", "{#5DC9E2}"
case fmtc.Is256ColorsSupported():
colorTagApp, colorTagVer = "{*}{#38}", "{#74}"
default:
colorTagApp, colorTagVer = "{*}{c}", "{c}"
}
}

// configureSignalHandlers configures signal handlers
Expand Down Expand Up @@ -237,26 +248,21 @@ func isShutdownMessage(data string) bool {
}

// printError prints error message to console
func printError(f string, a ...interface{}) {
func printError(f string, a ...any) {
fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...)
}

// printError prints warning message to console
func printWarn(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{y}"+f+"{!}\n", a...)
}

// ////////////////////////////////////////////////////////////////////////////////// //

// printCompletion prints completion for given shell
func printCompletion() int {
switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(genUsage(), APP))
fmt.Print(bash.Generate(genUsage(), APP))
case "fish":
fmt.Printf(fish.Generate(genUsage(), APP))
fmt.Print(fish.Generate(genUsage(), APP))
case "zsh":
fmt.Printf(zsh.Generate(genUsage(), optMap, APP))
fmt.Print(zsh.Generate(genUsage(), optMap, APP))
default:
return 1
}
Expand All @@ -282,17 +288,27 @@ func genUsage() *usage.Info {
info.AddOption(OPT_HELP, "Show this help message")
info.AddOption(OPT_VER, "Show version")

info.AddRawExample(
"go-fuzz -bin app-fuzz.zip |& fz",
"Run fuzz test for app-fuzz.zip",
)

return info
}

// genAbout generates info about version
func genAbout(gitRev string) *usage.About {
about := &usage.About{
App: APP,
Version: VER,
Desc: DESC,
Year: 2009,
Owner: "ESSENTIAL KAOS",
App: APP,
Version: VER,
Desc: DESC,
Year: 2009,
Owner: "ESSENTIAL KAOS",

AppNameColorTag: colorTagApp,
VersionColorTag: colorTagVer,
DescSeparator: "{s}—{!}",

License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",
UpdateChecker: usage.UpdateChecker{"essentialkaos/fz", update.GitHubChecker},
}
Expand Down
60 changes: 39 additions & 21 deletions cli/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package support

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"runtime"
"runtime/debug"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
Expand All @@ -24,9 +25,9 @@ import (

// ////////////////////////////////////////////////////////////////////////////////// //

// ShowSupportInfo prints verbose info about application, system, dependencies and
// Print prints verbose info about application, system, dependencies and
// important environment
func ShowSupportInfo(app, ver, gitRev string, gomod []byte) {
func Print(app, ver, gitRev string, gomod []byte) {
fmtutil.SeparatorTitleColorTag = "{s-}"
fmtutil.SeparatorFullscreen = false
fmtutil.SeparatorColorTag = "{s-}"
Expand Down Expand Up @@ -55,6 +56,10 @@ func showApplicationInfo(app, ver, gitRev string) {
runtime.GOOS, runtime.GOARCH,
))

if gitRev == "" {
gitRev = extractGitRevFromBuildInfo()
}

if gitRev != "" {
if !fmtc.DisableColors && fmtc.IsTrueColorSupported() {
printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev))
Expand All @@ -80,7 +85,19 @@ func showApplicationInfo(app, ver, gitRev string) {
func showEnvInfo() {
fmtutil.Separator(false, "ENVIRONMENT")

printInfo(6, "Golang", getGOVersion())
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
Expand All @@ -102,6 +119,23 @@ func showDepsInfo(gomod []byte) {
}
}

// 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 {
Expand All @@ -113,7 +147,7 @@ func getHashColorBullet(v string) string {

// printInfo formats and prints info record
func printInfo(size int, name, value string) {
name = name + ":"
name += ":"
size++

if value == "" {
Expand All @@ -126,19 +160,3 @@ func printInfo(size int, name, value string) {
}

// ////////////////////////////////////////////////////////////////////////////////// //

// getGOVersion returns version of installed Go
func getGOVersion() string {
cmd := exec.Command("go", "version")
out, err := cmd.Output()

if err != nil {
return ""
}

goVer := strings.Trim(string(out), "\n\t\r")
goVer = strutil.ReadField(goVer, 2, false, " ")
goVer = strutil.Exclude(goVer, "go")

return goVer
}
Loading

0 comments on commit cba41aa

Please sign in to comment.