Skip to content

Commit

Permalink
Merge pull request #32 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
andyone authored Aug 10, 2022
2 parents dd6e07b + 6a4b826 commit 1da0d52
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 55 deletions.
22 changes: 6 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:

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

strategy:
matrix:
Expand All @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
73 changes: 58 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,48 +9,91 @@

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

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'

################################################################################
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion common/uc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,6 +64,11 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Wed Aug 10 2022 Anton Novojilov <[email protected]> - 1.1.0-0
- Minor UI improvements
- Fixed bug with parsing max number of unique lines
- Updated dependencies

* Tue Mar 29 2022 Anton Novojilov <[email protected]> - 1.0.1-0
- Removed pkg.re usage
- Added module info
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 11 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
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=
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=
Expand Down
16 changes: 10 additions & 6 deletions uc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -158,7 +158,7 @@ func main() {
signal.QUIT: signalHandler,
}.TrackAsync()

processData(args[0])
processData(args.Get(0).String())
}

// configureUI configures user interface
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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",
Expand Down

0 comments on commit 1da0d52

Please sign in to comment.