diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11cfebd..5a792aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,6 @@ jobs: env: SRC_DIR: src/github.com/${{ github.repository }} - GO111MODULE: auto strategy: matrix: @@ -26,13 +25,6 @@ jobs: uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - id: go - - - name: Setup PATH - run: | - echo "GOPATH=${{ github.workspace }}" >> "$GITHUB_ENV" - echo "GOBIN=${{ github.workspace }}/bin" >> "$GITHUB_ENV" - echo "${{ github.workspace }}/bin" >> "$GITHUB_PATH" - name: Checkout uses: actions/checkout@v3 @@ -57,16 +49,14 @@ jobs: - name: Code checkout uses: actions/checkout@v3 - - name: Login to DockerHub - uses: docker/login-action@v1 - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - if: ${{ env.DOCKERHUB_USERNAME != '' }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Check specs with Perfecto - uses: essentialkaos/perfecto-action@v1 + uses: essentialkaos/perfecto-action@v2 with: files: common/uc.spec diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 0fa9f18..bf5ecc9 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -25,9 +25,9 @@ jobs: fetch-depth: 2 - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: go - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/Makefile b/Makefile index 2645cd5..adf6605 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ################################################################################ -# This Makefile generated by GoMakeGen 1.5.1 using next command: +# This Makefile generated by GoMakeGen 2.1.0 using next command: # gomakegen --mod . # # More info: https://kaos.sh/gomakegen @@ -9,15 +9,24 @@ export GO111MODULE=on +ifdef VERBOSE ## Print verbose information (Flag) +VERBOSE_FLAG = -v +endif + +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 mod-init mod-update mod-vendor help +.PHONY = fmt vet all clean deps update init vendor mod-init mod-update mod-download mod-vendor help ################################################################################ all: uc ## Build all binaries -uc: ## Build uc binary - go build uc.go +uc: + go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" uc.go install: ## Install all binaries cp uc /usr/bin/uc @@ -25,32 +34,66 @@ install: ## Install all binaries uninstall: ## Uninstall all binaries rm -f /usr/bin/uc -deps: mod-update ## Download dependencies +init: mod-init ## Initialize new module -mod-init: ## Initialize new module - go mod init - go mod tidy +deps: mod-download ## Download dependencies + +update: mod-update ## Update dependencies to the latest versions -mod-update: ## Download modules to local cache +vendor: mod-vendor ## Make vendored copy of dependencies + +mod-init: +ifdef MODULE_PATH ## Module path for initialization (String) + go mod init $(MODULE_PATH) +else + go mod init +endif + +ifdef COMPAT ## Compatible Go version (String) + go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) +else + go mod tidy $(VERBOSE_FLAG) +endif + +mod-update: +ifdef UPDATE_ALL ## Update all dependencies (Flag) + go get -u $(VERBOSE_FLAG) all +else + go get -u $(VERBOSE_FLAG) ./... +endif + +ifdef COMPAT + go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) +else + go mod tidy $(VERBOSE_FLAG) +endif + + test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : + +mod-download: go mod download -mod-vendor: ## Make vendored copy of dependencies - go mod vendor +mod-vendor: + rm -rf vendor && go mod vendor $(VERBOSE_FLAG) fmt: ## Format source code with gofmt find . -name "*.go" -exec gofmt -s -w {} \; -vet: ## Runs go vet over sources +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 ./... clean: ## Remove generated files rm -f uc help: ## Show this info - @echo -e '\n\033[1mSupported targets:\033[0m\n' + @echo -e '\n\033[1mTargets:\033[0m\n' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ - | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-12s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-14s\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}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 1.5.1\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 2.1.0\033[0m\n' ################################################################################ diff --git a/README.md b/README.md index 47b6633..78fedc5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ### Usage demo -[![demo](https://gh.kaos.st/uc-001.gif)](#usage-demo) +[![demo](https://gh.kaos.st/uc-110.gif)](#usage-demo) ### Installation @@ -88,7 +88,7 @@ Usage: uc {options} file Options --dist, -d Show number of occurrences for every line - --max, -m num Max number of unique lines (default: 5000) + --max, -m num Max number of unique lines --no-progress, -np Disable progress output --no-progress, -np Disable progress output --no-color, -nc Disable colors in output @@ -104,11 +104,10 @@ Examples Show distribution for file.txt uc -d -m 5k file.txt - Show distribution for file.txt for 5,000 uniq lines max + Show distribution for file.txt with 5,000 uniq lines max cat file.txt | uc - Count unique lines in stdin data - ``` ### Build Status diff --git a/common/uc.spec b/common/uc.spec index 07a6af4..c216101 100644 --- a/common/uc.spec +++ b/common/uc.spec @@ -10,7 +10,7 @@ Summary: Simple utility for counting unique lines Name: uc -Version: 1.0.1 +Version: 1.1.0 Release: 0%{?dist} Group: Applications/System License: Apache License, Version 2.0 @@ -64,6 +64,11 @@ rm -rf %{buildroot} ################################################################################ %changelog +* Wed Aug 10 2022 Anton Novojilov - 1.1.0-0 +- Minor UI improvements +- Fixed bug with parsing max number of unique lines +- Updated dependencies + * Tue Mar 29 2022 Anton Novojilov - 1.0.1-0 - Removed pkg.re usage - Added module info diff --git a/go.mod b/go.mod index e0e252e..410473f 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,6 @@ module github.com/essentialkaos/uc go 1.17 -require github.com/essentialkaos/ek/v12 v12.43.0 +require github.com/essentialkaos/ek/v12 v12.53.0 -require golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect +require golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b // indirect diff --git a/go.sum b/go.sum index fd56d8f..425e2c8 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,9 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/essentialkaos/check v1.2.1 h1:avvyFy/1acUNwfxwuOLsHeCjfXtMygtbu0lVDr3nxFs= -github.com/essentialkaos/check v1.2.1/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8= -github.com/essentialkaos/ek/v12 v12.43.0 h1:lnwrfGYQFJ3EjEF4ydW2qnshDcXCR2OnNRk0kwlFpFE= -github.com/essentialkaos/ek/v12 v12.43.0/go.mod h1:Cv/tOZshmFg4pMJnBkg4aW/WyYhzzc41qzZIfk5RSi4= -github.com/essentialkaos/go-linenoise/v3 v3.3.5/go.mod h1:g4X3LhT83XT4h7xwrCLclAdMkJvS9qWBQTGNdS6y4vo= +github.com/essentialkaos/check v1.3.0 h1:ria+8o22RCLdt2D/1SHQsEH5Mmy5S+iWHaGHrrbPUc0= +github.com/essentialkaos/check v1.3.0/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8= +github.com/essentialkaos/ek/v12 v12.53.0 h1:sBSzM4ZQ487wRqAIB7kfftqMSi8/HXIr5exJlBbdljA= +github.com/essentialkaos/ek/v12 v12.53.0/go.mod h1:Y8ln7hqABw8GT1vWuU7cCJfZAdE1uxmOYZvOVv8HRzo= +github.com/essentialkaos/go-linenoise/v3 v3.4.0/go.mod h1:t1kNLY2bSMQCy1JXOefD2BDLs/TTPMtTv3DFNV5uDSI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= @@ -11,15 +11,17 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= +github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= -golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b h1:2n253B2r0pYSmEV+UNCQoPfU/FiaizQEK5Gu4Bq4JE8= +golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/uc.go b/uc.go index a512cfb..4393f12 100644 --- a/uc.go +++ b/uc.go @@ -38,7 +38,7 @@ import ( // Application basic info const ( APP = "uc" - VER = "1.0.1" + VER = "1.1.0" DESC = "Tool for counting unique lines" ) @@ -96,7 +96,7 @@ func (s linesSlice) Less(i, j int) bool { // optMap is map with options var optMap = options.Map{ - OPT_MAX_LINES: {Type: options.MIXED}, + OPT_MAX_LINES: {Type: options.INT}, OPT_DISTRIBUTION: {Type: options.BOOL}, OPT_NO_PROGRESS: {Type: options.BOOL}, OPT_NO_COLOR: {Type: options.BOOL}, @@ -158,7 +158,7 @@ func main() { signal.QUIT: signalHandler, }.TrackAsync() - processData(args[0]) + processData(args.Get(0).String()) } // configureUI configures user interface @@ -257,7 +257,7 @@ func readData(s *bufio.Scanner) { // printProgress shows data processing progress func printProgress() { - for range time.NewTicker(time.Second / 5).C { + for range time.NewTicker(time.Second / 4).C { stats.mx.Lock() if stats.Finished { @@ -316,6 +316,10 @@ func printDistribution() { // parseMaxLines parses max line option func parseMaxLines(maxLines string) (int, error) { + if maxLines == "" { + return 0, nil + } + maxLines = strings.ToUpper(maxLines) mp := 1 @@ -392,7 +396,7 @@ func genUsage() *usage.Info { info := usage.NewInfo(APP, "file") info.AddOption(OPT_DISTRIBUTION, "Show number of occurrences for every line") - info.AddOption(OPT_MAX_LINES, "Max number of unique lines {s-}(default: 5000){!}", "num") + info.AddOption(OPT_MAX_LINES, "Max number of unique lines", "num") info.AddOption(OPT_NO_PROGRESS, "Disable progress output") info.AddOption(OPT_NO_PROGRESS, "Disable progress output") info.AddOption(OPT_NO_COLOR, "Disable colors in output") @@ -401,7 +405,7 @@ func genUsage() *usage.Info { info.AddExample("file.txt", "Count unique lines in file.txt") info.AddExample("-d file.txt", "Show distribution for file.txt") - info.AddExample("-d -m 5k file.txt", "Show distribution for file.txt for 5,000 uniq lines max") + 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",