Skip to content

Commit

Permalink
Merge pull request #48 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
andyone authored May 11, 2023
2 parents d50a955 + 7436b39 commit 6f176f5
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 35 deletions.
39 changes: 39 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "2"

checks:
argument-count:
enabled: true
config:
threshold: 6
complex-logic:
enabled: true
config:
threshold: 6
file-lines:
enabled: true
config:
threshold: 1000
method-complexity:
enabled: true
config:
threshold: 8
method-count:
enabled: true
config:
threshold: 20
method-lines:
enabled: true
config:
threshold: 100
nested-control-flow:
enabled: true
config:
threshold: 6
return-statements:
enabled: true
config:
threshold: 6
similar-code:
enabled: false
identical-code:
enabled: false
26 changes: 16 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

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

jobs:
Go:
name: Go
Expand All @@ -37,22 +34,18 @@ jobs:
go: [ '1.19.x', '1.20.x' ]

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

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

- name: Checkout
uses: actions/checkout@v3
with:
path: ${{env.SRC_DIR}}

- name: Download dependencies
working-directory: ${{env.SRC_DIR}}
run: make deps

- name: Build binary
working-directory: ${{env.SRC_DIR}}
run: make all

Perfecto:
Expand All @@ -76,3 +69,16 @@ jobs:
uses: essentialkaos/perfecto-action@v2
with:
files: common/uc.spec

Typos:
name: Typos
runs-on: ubuntu-latest

needs: Go

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

- name: Check spelling
uses: crate-ci/typos@master
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[files]
extend-exclude = ["go.sum"]
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<p align="center"><a href="#readme"><img src="https://gh.kaos.st/uc.svg"/></a></p>

<p align="center">
<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/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>
</p>
Expand All @@ -22,7 +23,7 @@

#### From sources

To build the `uc` from scratch, make sure you have a working Go 1.19+ workspace (_[instructions](https://golang.org/doc/install)_), then:
To build the `uc` from scratch, make sure you have a working Go 1.19+ workspace (_[instructions](https://go.dev/doc/install)_), then:

```
go install github.com/essentialkaos/uc@latest
Expand Down Expand Up @@ -100,7 +101,7 @@ Examples
uc -d -m 5k file.txt
Show distribution for file.txt with 5,000 uniq lines max
cat file.txt | uc -
cat file.txt | uc
Count unique lines in stdin data
```

Expand Down
39 changes: 28 additions & 11 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
// Application basic info
const (
APP = "uc"
VER = "1.1.1"
VER = "2.0.0"
DESC = "Tool for counting unique lines"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ var optMap = options.Map{
OPT_NO_PROGRESS: {Type: options.BOOL},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

OPT_VERB_VER: {Type: options.BOOL},
OPT_COMPLETION: {},
Expand Down Expand Up @@ -141,12 +141,12 @@ func Run(gitRev string, gomod []byte) {
printMan()
os.Exit(0)
case options.GetB(OPT_VER):
genAbout(gitRev).Print()
genAbout(gitRev).Print(options.GetS(OPT_VER))
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.Print(APP, VER, gitRev, gomod)
os.Exit(0)
case options.GetB(OPT_HELP) || len(args) == 0:
case options.GetB(OPT_HELP):
genUsage().Print()
os.Exit(0)
}
Expand All @@ -157,7 +157,7 @@ func Run(gitRev string, gomod []byte) {
signal.QUIT: signalHandler,
}.TrackAsync()

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

// preConfigureUI preconfigures UI based on information about user terminal
Expand Down Expand Up @@ -197,14 +197,16 @@ func configureUI() {
}

// processData starts data processing
func processData(input string) {
func processData(args options.Arguments) {
var r *bufio.Reader

stats = &Stats{
Counters: make(map[uint64]uint32),
mx: &sync.Mutex{},
}

input := getInput(args)

if input == "-" {
r = bufio.NewReader(os.Stdin)
} else {
Expand All @@ -221,6 +223,23 @@ func processData(input string) {
readData(bufio.NewScanner(r))
}

// getInput returns input for reading data
func getInput(args options.Arguments) string {
if args.Get(0).String() == "-" || !fsutil.IsCharacterDevice("/dev/stdin") {
return "-"
}

input := args.Get(0).Clean().String()
err := fsutil.ValidatePerms("FRS", input)

if err != nil {
printError(err.Error())
os.Exit(1)
}

return input
}

// readData reads data
func readData(s *bufio.Scanner) {
ct := crc64.MakeTable(crc64.ECMA)
Expand Down Expand Up @@ -319,7 +338,7 @@ func printResults() {
stats.mx.Unlock()
}

// printDistribution prints distrubution info
// printDistribution prints distribution info
func printDistribution() {
var distData linesSlice

Expand Down Expand Up @@ -416,10 +435,8 @@ 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 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")

return info
}
Expand Down
5 changes: 4 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: 1.1.1
Version: 2.0.0
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
Expand Down Expand Up @@ -65,6 +65,9 @@ rm -rf %{buildroot}
################################################################################

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

* Mon Mar 06 2023 Anton Novojilov <[email protected]> - 1.1.1-0
- Added verbose info output
- Dependencies update
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/essentialkaos/uc
go 1.18

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

require golang.org/x/sys v0.6.0 // indirect
require golang.org/x/sys v0.8.0 // indirect
14 changes: 7 additions & 7 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.0.0 h1:FikBtTnNhk+xFO/hFr+CfiKs6QnA3wMD6tGL0XTEUkc=
github.com/essentialkaos/depsy v1.0.0/go.mod h1:XVsB2eVUonEzmLKQP3ig2P6v2+WcHVgJ10zm0JLqFMM=
github.com/essentialkaos/ek/v12 v12.63.0 h1:9yaEu5W3bx//9y52ShqYCoFDKOcwEdrnvgSkUYyatgI=
github.com/essentialkaos/ek/v12 v12.63.0/go.mod h1:9MlSuHpewu7OZ9tM9dLFHvoA8dflBIUPCA0Ctt97wRs=
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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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=

0 comments on commit 6f176f5

Please sign in to comment.