Skip to content

Commit

Permalink
Merge pull request #83 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.1
  • Loading branch information
andyone authored Dec 19, 2023
2 parents 6f176f5 + 5c30378 commit cdc2c3a
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 62 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:

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

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

Expand All @@ -56,10 +56,10 @@ jobs:

steps:
- name: Code checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -78,7 +78,8 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
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
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 @@ -50,7 +51,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 @@ -94,6 +95,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'

################################################################################
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ To build the `uc` from scratch, make sure you have a working Go 1.19+ workspace
go install github.com/essentialkaos/uc@latest
```

#### From [ESSENTIAL KAOS Public Repository](https://yum.kaos.st)
#### From [ESSENTIAL KAOS Public Repository](https://pkgs.kaos.st)

```bash
sudo yum install -y https://yum.kaos.st/kaos-repo-latest.el$(grep 'CPE_NAME' /etc/os-release | tr -d '"' | cut -d':' -f5).noarch.rpm
sudo yum install -y https://pkgs.kaos.st/kaos-repo-latest.el$(grep 'CPE_NAME' /etc/os-release | tr -d '"' | cut -d':' -f5).noarch.rpm
sudo yum install uc
```

Expand Down Expand Up @@ -103,6 +103,9 @@ Examples
cat file.txt | uc
Count unique lines in stdin data
uc -m 100 < file.txt
Count unique lines in stdin data with 100 uniq lines max
```

### Build Status
Expand Down
64 changes: 36 additions & 28 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/signal"
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
"github.com/essentialkaos/ek/v12/usage/completion/fish"
Expand All @@ -40,7 +41,7 @@ import (
// Application basic info
const (
APP = "uc"
VER = "2.0.0"
VER = "2.0.1"
DESC = "Tool for counting unique lines"
)

Expand Down Expand Up @@ -117,6 +118,12 @@ var stats *Stats
// rawMode is raw mode flag
var rawMode bool

// colorTagApp contains color tag for app name
var colorTagApp string

// colorTagVer contains color tag for app version
var colorTagVer string

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

// Run is main application function
Expand Down Expand Up @@ -162,27 +169,10 @@ func Run(gitRev string, gomod []byte) {

// preConfigureUI preconfigures UI based on information about user terminal
func preConfigureUI() {
term := os.Getenv("TERM")

fmtc.DisableColors = true

if term != "" {
switch {
case strings.Contains(term, "xterm"),
strings.Contains(term, "color"),
term == "screen":
fmtc.DisableColors = false
}
}

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
if !tty.IsTTY() {
fmtc.DisableColors = true
rawMode = true
}

if os.Getenv("NO_COLOR") != "" {
fmtc.DisableColors = true
}
}

// configureUI configures user interface
Expand All @@ -194,6 +184,13 @@ func configureUI() {
if options.GetB(OPT_NO_PROGRESS) {
rawMode = true
}

switch {
case fmtc.Is256ColorsSupported():
colorTagApp, colorTagVer = "{*}{#168}", "{#168}"
default:
colorTagApp, colorTagVer = "{*}{m}", "{m}"
}
}

// processData starts data processing
Expand Down Expand Up @@ -398,11 +395,11 @@ func printError(f string, a ...interface{}) {
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 @@ -424,6 +421,8 @@ func printMan() {
func genUsage() *usage.Info {
info := usage.NewInfo(APP, "file")

info.AppNameColorTag = colorTagApp

info.AddOption(OPT_DISTRIBUTION, "Show number of occurrences for every line")
info.AddOption(OPT_MAX_LINES, "Max number of unique lines", "num")
info.AddOption(OPT_NO_PROGRESS, "Disable progress output")
Expand All @@ -436,19 +435,28 @@ func genUsage() *usage.Info {
info.AddExample("-d file.txt", "Show distribution for file.txt")
info.AddExample("-d -m 5k file.txt", "Show distribution for file.txt with 5,000 uniq lines max")
info.AddRawExample("cat file.txt | "+APP, "Count unique lines in stdin data")
info.AddRawExample(APP+" -m 100 < file.txt", "Count unique lines in stdin data with 100 uniq lines max")

info.AddRawExample(
APP+" -m 100 < file.txt",
"Count unique lines in stdin data with 100 uniq lines max",
)

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>",
BugTracker: "https://github.com/essentialkaos/uc",
UpdateChecker: usage.UpdateChecker{"essentialkaos/uc", update.GitHubChecker},
Expand Down
49 changes: 36 additions & 13 deletions cli/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"fmt"
"os"
"runtime"
"runtime/debug"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/fmtutil"
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/hash"
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/system"
"github.com/essentialkaos/ek/v12/system/container"

"github.com/essentialkaos/depsy"
)
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 Down Expand Up @@ -83,37 +88,38 @@ func showOSInfo() {
if err == nil {
fmtutil.Separator(false, "OS INFO")

printInfo(12, "Name", osInfo.Name)
printInfo(12, "Pretty Name", osInfo.PrettyName)
printInfo(12, "Version", osInfo.VersionID)
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)
}
} 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 {
case fsutil.IsExist("/.dockerenv"):
switch container.GetEngine() {
case container.DOCKER:
containerEngine = "Yes (Docker)"
case fsutil.IsExist("/run/.containerenv"):
case container.PODMAN:
containerEngine = "Yes (Podman)"
case container.LXC:
containerEngine = "Yes (LXC)"
}

fmtc.NewLine()
Expand All @@ -140,6 +146,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 @@ -151,7 +174,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 Down
6 changes: 5 additions & 1 deletion common/uc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Summary: Simple utility for counting unique lines
Name: uc
Version: 2.0.0
Version: 2.0.1
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
Expand Down Expand Up @@ -65,6 +65,10 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Tue Dec 19 2023 Anton Novojilov <[email protected]> - 2.0.1-0
- Dependencies update
- Code refactoring

* Wed May 03 2023 Anton Novojilov <[email protected]> - 2.0.0-0
- Better standard input handling

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.67.0
github.com/essentialkaos/ek/v12 v12.92.0
)

require golang.org/x/sys v0.8.0 // indirect
require golang.org/x/sys v0.15.0 // indirect
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
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.67.0 h1:ii15t0O+3Mu7uI3Te5X5BIqYXi1V7ovtSIYi5LyiltU=
github.com/essentialkaos/ek/v12 v12.67.0/go.mod h1:sRgw+F7PeeoNsmLLVMKy5ccugwGSljk8/rTXC9dyT+M=
github.com/essentialkaos/ek/v12 v12.92.0 h1:3JIkHWNA6MNkJOfqzMWJ8jN9sRM7nRi7URoFRVFHZzI=
github.com/essentialkaos/ek/v12 v12.92.0/go.mod h1:9efMqo1S8EtYhmeelOSTmMQDGC2vRgPkjkKKfvUD2eU=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit cdc2c3a

Please sign in to comment.