diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index fc51337..d0ad1de 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -14,6 +14,12 @@ updates:
- "andyone"
reviewers:
- "andyone"
+ groups:
+ all:
+ applies-to: version-updates
+ update-types:
+ - "minor"
+ - "patch"
- package-ecosystem: "github-actions"
directory: "/"
diff --git a/.github/images/card.svg b/.github/images/card.svg
new file mode 100644
index 0000000..55420b2
--- /dev/null
+++ b/.github/images/card.svg
@@ -0,0 +1,4 @@
+
diff --git a/.github/images/license.svg b/.github/images/license.svg
new file mode 100644
index 0000000..8990e77
--- /dev/null
+++ b/.github/images/license.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/.github/images/usage.svg b/.github/images/usage.svg
new file mode 100644
index 0000000..b44fd32
--- /dev/null
+++ b/.github/images/usage.svg
@@ -0,0 +1,80 @@
+
+
diff --git a/Makefile b/Makefile
index 17726e0..cceec73 100644
--- a/Makefile
+++ b/Makefile
@@ -1,39 +1,40 @@
################################################################################
-# This Makefile generated by GoMakeGen 2.3.0 using next command:
+# This Makefile generated by GoMakeGen 3.0.4 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen
################################################################################
-export GO111MODULE=on
-
ifdef VERBOSE ## Print verbose information (Flag)
VERBOSE_FLAG = -v
endif
-COMPAT ?= 1.18
+COMPAT ?= 1.19
MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)
################################################################################
.DEFAULT_GOAL := help
-.PHONY = fmt vet all clean deps update init vendor mod-init mod-update mod-download mod-vendor help
+.PHONY = fmt vet all install uninstall clean deps update init vendor mod-init mod-update mod-download mod-vendor help
################################################################################
all: uc ## Build all binaries
uc:
- go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" uc.go
+ @echo "[36;1mBuilding uc…[0m"
+ @go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" uc.go
install: ## Install all binaries
- cp uc /usr/bin/uc
+ @echo "[36;1mInstalling binaries…[0m"
+ @cp uc /usr/bin/uc
uninstall: ## Uninstall all binaries
- rm -f /usr/bin/uc
+ @echo "[36;1mRemoving installed binaries…[0m"
+ @rm -f /usr/bin/uc
init: mod-init ## Initialize new module
@@ -44,57 +45,70 @@ update: mod-update ## Update dependencies to the latest versions
vendor: mod-vendor ## Make vendored copy of dependencies
mod-init:
+ @echo "[37m[1/2][0m [36;1mModules initialization…[0m"
ifdef MODULE_PATH ## Module path for initialization (String)
- go mod init $(MODULE_PATH)
+ @go mod init $(MODULE_PATH)
else
- go mod init
+ @go mod init
endif
+ @echo "[37m[2/2][0m [36;1mDependencies cleanup…[0m"
ifdef COMPAT ## Compatible Go version (String)
- go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
+ @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
else
- go mod tidy $(VERBOSE_FLAG)
+ @go mod tidy $(VERBOSE_FLAG)
endif
mod-update:
+ @echo "[37m[1/4][0m [36;1mUpdating dependencies…[0m"
ifdef UPDATE_ALL ## Update all dependencies (Flag)
- go get -u $(VERBOSE_FLAG) all
+ @go get -u $(VERBOSE_FLAG) all
else
- go get -u $(VERBOSE_FLAG) ./...
+ @go get -u $(VERBOSE_FLAG) ./...
endif
+ @echo "[37m[2/4][0m [36;1mStripping toolchain info…[0m"
+ @grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || :
+
+ @echo "[37m[3/4][0m [36;1mDependencies cleanup…[0m"
ifdef COMPAT
- go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
+ @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT)
else
- go mod tidy $(VERBOSE_FLAG)
+ @go mod tidy $(VERBOSE_FLAG)
endif
- test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :
+ @echo "[37m[4/4][0m [36;1mUpdating vendored dependencies…[0m"
+ @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :
mod-download:
- go mod download
+ @echo "[36;1mDownloading dependencies…[0m"
+ @go mod download
mod-vendor:
- rm -rf vendor && go mod vendor $(VERBOSE_FLAG)
+ @echo "[36;1mVendoring dependencies…[0m"
+ @rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :
fmt: ## Format source code with gofmt
- find . -name "*.go" -exec gofmt -s -w {} \;
+ @echo "[36;1mFormatting sources…[0m"
+ @find . -name "*.go" -exec gofmt -s -w {} \;
vet: ## Runs 'go vet' over sources
- go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./...
+ @echo "[36;1mRunning 'go vet' over sources…[0m"
+ @go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./...
clean: ## Remove generated files
- rm -f uc
+ @echo "[36;1mRemoving built binaries…[0m"
+ @rm -f uc
help: ## Show this info
@echo -e '\n\033[1mTargets:\033[0m\n'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
- | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-14s\033[0m %s\n", $$1, $$2}'
+ | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-9s\033[0m %s\n", $$1, $$2}'
@echo -e '\n\033[1mVariables:\033[0m\n'
@grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \
| sed 's/ifdef //' \
- | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
+ | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}'
@echo -e ''
- @echo -e '\033[90mGenerated by GoMakeGen 2.3.0\033[0m\n'
+ @echo -e '\033[90mGenerated by GoMakeGen 3.0.4\033[0m\n'
################################################################################
diff --git a/README.md b/README.md
index 25e951e..1ff8757 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-

+
@@ -6,7 +6,7 @@
-
+
Usage demo • Installation • Command-line completion • Usage • Contributing • License
@@ -97,38 +97,7 @@ uc --generate-man | sudo gzip > /usr/share/man/man1/uc.1.gz
### Usage
-```
-Usage: uc {options} file
-
-Options
-
- --dist, -d format Show number of occurrences for every line (-/simple/table/json)
- --max, -m num Max number of unique lines
- --no-progress, -np Disable progress output
- --no-color, -nc Disable colors in output
- --help, -h Show this help message
- --version, -v Show version
-
-Examples
-
- uc file.txt
- Count unique lines in file.txt
-
- uc -d file.txt
- Show distribution for file.txt
-
- uc --dist=table file.txt
- Show distribution as a table for file.txt
-
- uc -d -m 5k file.txt
- Show distribution for file.txt with 5,000 uniq lines max
-
- 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
diff --git a/cli/cli.go b/cli/cli.go
index 295933a..2a84da0 100644
--- a/cli/cli.go
+++ b/cli/cli.go
@@ -28,6 +28,7 @@ import (
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/support"
"github.com/essentialkaos/ek/v12/support/deps"
+ "github.com/essentialkaos/ek/v12/terminal"
"github.com/essentialkaos/ek/v12/terminal/tty"
"github.com/essentialkaos/ek/v12/usage"
"github.com/essentialkaos/ek/v12/usage/completion/bash"
@@ -44,7 +45,7 @@ import (
// Application basic info
const (
APP = "uc"
- VER = "3.0.1"
+ VER = "3.0.2"
DESC = "Tool for counting unique lines"
)
@@ -137,8 +138,9 @@ func Run(gitRev string, gomod []byte) {
args, errs := options.Parse(optMap)
- if len(errs) != 0 {
- printError(errs[0].Error())
+ if !errs.IsEmpty() {
+ terminal.Error("Options parsing errors:")
+ terminal.Error(errs.String())
os.Exit(1)
}
@@ -220,7 +222,7 @@ func processData(args options.Arguments) {
fd, err := os.OpenFile(input, os.O_RDONLY, 0)
if err != nil {
- printError(err.Error())
+ terminal.Error(err)
os.Exit(1)
}
@@ -237,7 +239,7 @@ func getInput(args options.Arguments) string {
err := fsutil.ValidatePerms("FRS", input)
if err != nil {
- printError(err.Error())
+ terminal.Error(err)
os.Exit(1)
}
@@ -250,7 +252,7 @@ func readData(s *bufio.Scanner) {
maxLines, err := parseMaxLines(options.GetS(OPT_MAX_LINES))
if err != nil {
- printError(err.Error())
+ terminal.Error(err)
os.Exit(1)
}
@@ -441,11 +443,6 @@ func signalHandler() {
os.Exit(0)
}
-// printError prints error message to console
-func printError(f string, a ...interface{}) {
- fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...)
-}
-
// ////////////////////////////////////////////////////////////////////////////////// //
// printCompletion prints completion for given shell
@@ -491,8 +488,8 @@ func genUsage() *usage.Info {
info.AddExample("-d file.txt", "Show distribution for file.txt")
info.AddExample("--dist=table file.txt", "Show distribution as a table 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("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",
diff --git a/common/uc.spec b/common/uc.spec
index 80c0969..8158a5c 100644
--- a/common/uc.spec
+++ b/common/uc.spec
@@ -6,7 +6,7 @@
Summary: Simple utility for counting unique lines
Name: uc
-Version: 3.0.1
+Version: 3.0.2
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
@@ -16,7 +16,7 @@ Source0: https://source.kaos.st/%{name}/%{name}-%{version}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-BuildRequires: golang >= 1.20
+BuildRequires: golang >= 1.21
Provides: %{name} = %{version}-%{release}
@@ -28,14 +28,17 @@ Simple utility for counting unique lines.
################################################################################
%prep
-%setup -q
-%build
+%setup -q
if [[ ! -d "%{name}/vendor" ]] ; then
- echo "This package requires vendored dependencies"
+ echo -e "----\nThis package requires vendored dependencies\n----"
+ exit 1
+elif [[ -f "%{name}/%{name}" ]] ; then
+ echo -e "----\nSources must not contain precompiled binaries\n----"
exit 1
fi
+%build
pushd %{name}
go build %{name}.go
cp LICENSE ..
@@ -93,6 +96,10 @@ fi
################################################################################
%changelog
+* Mon Jun 24 2024 Anton Novojilov - 3.0.2-0
+- Code refactoring
+- Dependencies update
+
* Thu Mar 28 2024 Anton Novojilov - 3.0.1-0
- Improved support information gathering
- Code refactoring
diff --git a/go.mod b/go.mod
index 1879b66..ad99e0c 100644
--- a/go.mod
+++ b/go.mod
@@ -4,10 +4,10 @@ go 1.18
require (
github.com/cespare/xxhash v1.1.0
- github.com/essentialkaos/ek/v12 v12.113.1
+ github.com/essentialkaos/ek/v12 v12.127.0
)
require (
- github.com/essentialkaos/depsy v1.1.0 // indirect
- golang.org/x/sys v0.18.0 // indirect
+ github.com/essentialkaos/depsy v1.3.0 // indirect
+ golang.org/x/sys v0.21.0 // indirect
)
diff --git a/go.sum b/go.sum
index 5752aea..72cc6e4 100644
--- a/go.sum
+++ b/go.sum
@@ -3,14 +3,14 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
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.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg=
-github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U=
+github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU=
+github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
+github.com/essentialkaos/ek/v12 v12.127.0 h1:fU5A+QbIZ7NTq1K5jGVwAWwuLtBUhsIKuRWYT78hE+Q=
+github.com/essentialkaos/ek/v12 v12.127.0/go.mod h1:71IJ7m82hgjrvWnhL+z0vIhguxz47/rfVma5/CeI5Fw=
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.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
-golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
-golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
+golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=