Skip to content

Commit

Permalink
Merge pull request #116 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 3.0.2
  • Loading branch information
andyone authored Jun 24, 2024
2 parents bdc2983 + e4b2453 commit 90f54b4
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 85 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ updates:
- "andyone"
reviewers:
- "andyone"
groups:
all:
applies-to: version-updates
update-types:
- "minor"
- "patch"

- package-ecosystem: "github-actions"
directory: "/"
Expand Down
4 changes: 4 additions & 0 deletions .github/images/card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .github/images/license.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions .github/images/usage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 39 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 "Building uc…"
@go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" uc.go

install: ## Install all binaries
cp uc /usr/bin/uc
@echo "Installing binaries…"
@cp uc /usr/bin/uc

uninstall: ## Uninstall all binaries
rm -f /usr/bin/uc
@echo "Removing installed binaries…"
@rm -f /usr/bin/uc

init: mod-init ## Initialize new module

Expand All @@ -44,57 +45,70 @@ update: mod-update ## Update dependencies to the latest versions
vendor: mod-vendor ## Make vendored copy of dependencies

mod-init:
@echo "[1/2] Modules initialization…"
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 "[2/2] Dependencies cleanup…"
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 "[1/4] Updating dependencies…"
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 "[2/4] Stripping toolchain info…"
@grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || :

@echo "[3/4] Dependencies cleanup…"
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 "[4/4] Updating vendored dependencies…"
@test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

mod-download:
go mod download
@echo "Downloading dependencies…"
@go mod download

mod-vendor:
rm -rf vendor && go mod vendor $(VERBOSE_FLAG)
@echo "Vendoring dependencies…"
@rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || :

fmt: ## Format source code with gofmt
find . -name "*.go" -exec gofmt -s -w {} \;
@echo "Formatting sources…"
@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 "Running '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
@echo "Removing built binaries…"
@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'

################################################################################
37 changes: 3 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<p align="center"><a href="#readme"><img src="https://gh.kaos.st/uc.svg"/></a></p>
<p align="center"><a href="#readme"><img src=".github/images/card.svg"/></a></p>

<p align="center">
<a href="https://kaos.sh/r/uc"><img src="https://kaos.sh/r/uc.svg" alt="GoReportCard" /></a>
<a href="https://kaos.sh/l/uc"><img src="https://kaos.sh/l/29edb01c21de207a27ed.svg" alt="Code Climate Maintainability" /></a>
<a href="https://kaos.sh/b/uc"><img src="https://kaos.sh/b/fd8a50fa-575c-47ba-8c67-1dd2f3b437f7.svg" alt="codebeat badge" /></a>
<a href="https://kaos.sh/w/uc/ci"><img src="https://kaos.sh/w/uc/ci.svg" alt="GitHub Actions CI Status" /></a>
<a href="https://kaos.sh/w/uc/codeql"><img src="https://kaos.sh/w/uc/codeql.svg" alt="GitHub Actions CodeQL Status" /></a>
<a href="#license"><img src="https://gh.kaos.st/apache2.svg"></a>
<a href="#license"><img src=".github/images/license.svg"/></a>
</p>

<p align="center"><a href="#usage-demo">Usage demo</a> • <a href="#installation">Installation</a> • <a href="#command-line-completion">Command-line completion</a> • <a href="#usage">Usage</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a></p>
Expand Down Expand Up @@ -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
```
<img src=".github/images/usage.svg" />

### Build Status

Expand Down
21 changes: 9 additions & 12 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 90f54b4

Please sign in to comment.