Skip to content

Commit 87838d5

Browse files
authored
Merge pull request #20 from essentialkaos/develop
Version 0.3.0
2 parents 1e282e0 + f2f18b1 commit 87838d5

11 files changed

Lines changed: 142 additions & 22 deletions

File tree

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* @essentialkaos/go
2+
/.github/workflows/* @essentialkaos/devops

.github/dependabot.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ updates:
1212
- "PR • MAINTENANCE"
1313
assignees:
1414
- "andyone"
15-
reviewers:
16-
- "andyone"
1715
groups:
1816
all:
1917
applies-to: version-updates
@@ -32,5 +30,3 @@ updates:
3230
- "PR • MAINTENANCE"
3331
assignees:
3432
- "andyone"
35-
reviewers:
36-
- "andyone"

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
################################################################################
22

3-
# This Makefile generated by GoMakeGen 3.3.1 using next command:
3+
# This Makefile generated by GoMakeGen 3.3.3 using next command:
44
# gomakegen --mod .
55
#
66
# More info: https://kaos.sh/gomakegen
@@ -123,15 +123,15 @@ clean: ## Remove generated files
123123
@rm -f lj
124124

125125
help: ## Show this info
126-
@echo -e '\n\033[1mTargets:\033[0m\n'
126+
@printf '\n\033[1mTargets:\033[0m\n\n'
127127
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
128128
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-9s\033[0m %s\n", $$1, $$2}'
129-
@echo -e '\n\033[1mVariables:\033[0m\n'
129+
@printf '\n\033[1mVariables:\033[0m\n\n'
130130
@grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \
131131
| sed 's/ifdef //' \
132132
| sort -h \
133133
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}'
134-
@echo -e ''
135-
@echo -e '\033[90mGenerated by GoMakeGen 3.3.1\033[0m\n'
134+
@echo ''
135+
@printf '\033[90mGenerated by GoMakeGen 3.3.3\033[0m\n\n'
136136

137137
################################################################################

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<a href="#license"><img src=".github/images/license.svg"/></a>
77
</p>
88

9-
<p align="center"><a href="#installation">Installation</a> • <a href="#command-line-completion">Command-line completion</a> • <a href="#man-documentation">Man documentation</a> • <a href="#usage">Usage</a> • <a href="#ci-status">CI Status</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a></p>
9+
<p align="center"><a href="#installation">Installation</a> • <a href="#upgrading">Upgrading</a> • <a href="#usage">Usage</a> • <a href="#ci-status">CI Status</a> • <a href="#license">License</a></p>
1010

1111
<br/>
1212

@@ -34,6 +34,23 @@ You can download prebuilt binaries for Linux and macOS from [EK Apps Repository]
3434
bash <(curl -fsSL https://apps.kaos.st/get) lj
3535
```
3636

37+
### Upgrading
38+
39+
Since version `0.3.0` you can update `lj` to the latest release using [self-update feature](https://github.com/essentialkaos/.github/blob/master/APPS-UPDATE.md):
40+
41+
```bash
42+
lj --update
43+
```
44+
45+
This command will runs a self-update in interactive mode. If you want to run a quiet update (_no output_), use the following command:
46+
47+
```bash
48+
lj --update=quiet
49+
```
50+
51+
> [!NOTE]
52+
> Please note that the self-update feature only works with binaries that are downloaded from the [EK Apps Repository](https://apps.kaos.st/lj/latest). Binaries from packages do not have a self-update feature and must be upgraded via the package manager.
53+
3754
### Command-line completion
3855

3956
You can generate completion for `bash`, `zsh` or `fish` shell.

cli/cli.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
// Basic utility info
4040
const (
4141
APP = "lj"
42-
VER = "0.2.1"
42+
VER = "0.3.0"
4343
DESC = "Tool for viewing JSON logs"
4444
)
4545

@@ -55,6 +55,7 @@ const (
5555
OPT_HELP = "h:help"
5656
OPT_VER = "v:version"
5757

58+
OPT_UPDATE = "U:update"
5859
OPT_VERB_VER = "vv:verbose-version"
5960
OPT_COMPLETION = "completion"
6061
OPT_GENERATE_MAN = "generate-man"
@@ -91,6 +92,7 @@ var optMap = options.Map{
9192
OPT_HELP: {Type: options.BOOL},
9293
OPT_VER: {Type: options.MIXED},
9394

95+
OPT_UPDATE: {Type: options.MIXED},
9496
OPT_VERB_VER: {Type: options.BOOL},
9597
OPT_COMPLETION: {},
9698
OPT_GENERATE_MAN: {Type: options.BOOL},
@@ -146,12 +148,13 @@ var highlights Highlights
146148
// Run is main utility function
147149
func Run(gitRev string, gomod []byte) {
148150
preConfigureUI()
151+
preConfigureOptions()
149152

150153
args, errs := options.Parse(optMap)
151154

152155
if !errs.IsEmpty() {
153156
terminal.Error("Options parsing errors:")
154-
terminal.Error(errs.Error("- "))
157+
terminal.Error(errs.Error(" - "))
155158
os.Exit(1)
156159
}
157160

@@ -172,6 +175,8 @@ func Run(gitRev string, gomod []byte) {
172175
WithDeps(deps.Extract(gomod)).
173176
Print()
174177
os.Exit(0)
178+
case withSelfUpdate && options.GetB(OPT_UPDATE):
179+
os.Exit(updateBinary())
175180
case options.GetB(OPT_HELP) || (!hasStdinData() && len(args) == 0):
176181
genUsage().Print()
177182
os.Exit(0)
@@ -209,6 +214,11 @@ func preConfigureUI() {
209214
options.MergeSymbol = "\n"
210215
}
211216

217+
// preConfigureOptions preconfigures command-line options based on build tags
218+
func preConfigureOptions() {
219+
optMap.SetIf(withSelfUpdate, OPT_UPDATE, &options.V{Type: options.MIXED})
220+
}
221+
212222
// configureUI configures user interface
213223
func configureUI() {
214224
if options.GetB(OPT_NO_COLOR) {
@@ -295,7 +305,7 @@ func readDataStream(source *os.File, filters Filters) {
295305
line = strings.TrimRight(line, "\r\n")
296306

297307
if time.Since(lastPrint) > 30*time.Second {
298-
fmtutil.Separator(true, timeutil.ShortDuration(time.Since(lastPrint), false))
308+
fmtutil.Separator(true, timeutil.Pretty(time.Since(lastPrint)).Short(true))
299309
}
300310

301311
if renderLine(line, filters) {
@@ -513,6 +523,11 @@ func genUsage() *usage.Info {
513523
info.AddOption(OPT_FIND, "Find and highlight part of message {s}(repeatable){!}")
514524
info.AddOption(OPT_NO_PAGER, "Disable pager")
515525
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
526+
527+
if withSelfUpdate {
528+
info.AddOption(OPT_UPDATE, "Update application to the latest version")
529+
}
530+
516531
info.AddOption(OPT_HELP, "Show this help message")
517532
info.AddOption(OPT_VER, "Show version")
518533

cli/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func parseFilter(f string) Filter {
7777
}
7878

7979
if filter.Cond == COND_GREATER || filter.Cond == COND_LESS {
80-
fv, _ := strconv.ParseFloat(value, 10)
80+
fv, _ := strconv.ParseFloat(value, 64)
8181
filter.Value = fv
8282
} else {
8383
filter.Value = value

cli/with_selfupdate.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//go:build selfupdate
2+
// +build selfupdate
3+
4+
package cli
5+
6+
// ////////////////////////////////////////////////////////////////////////////////// //
7+
// //
8+
// Copyright (c) 2025 ESSENTIAL KAOS //
9+
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
10+
// //
11+
// ////////////////////////////////////////////////////////////////////////////////// //
12+
13+
import (
14+
"strings"
15+
16+
"github.com/essentialkaos/ek/v13/fmtc"
17+
"github.com/essentialkaos/ek/v13/options"
18+
"github.com/essentialkaos/ek/v13/selfupdate"
19+
"github.com/essentialkaos/ek/v13/selfupdate/interactive"
20+
storage "github.com/essentialkaos/ek/v13/selfupdate/storage/basic"
21+
"github.com/essentialkaos/ek/v13/terminal"
22+
)
23+
24+
// ////////////////////////////////////////////////////////////////////////////////// //
25+
26+
var withSelfUpdate = true
27+
28+
// ////////////////////////////////////////////////////////////////////////////////// //
29+
30+
// updateBinary updates current binary to the latest version
31+
func updateBinary() int {
32+
quiet := strings.ToLower(options.GetS(OPT_UPDATE)) == "quiet"
33+
updInfo, hasUpdate, err := storage.NewStorage("https://apps.kaos.ws").Check(APP, VER)
34+
35+
if err != nil {
36+
if !quiet {
37+
terminal.Error("Can't update binary: %v", err)
38+
}
39+
40+
return 1
41+
}
42+
43+
if !hasUpdate {
44+
fmtc.If(!quiet).Println("{g}You are using the latest version of the app{!}")
45+
return 0
46+
}
47+
48+
pubKey := "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEnYHsOTvrKqeE97dsEt7Ge97+yUcvQJn1++s++FqShDyqwV8CcoKp0E6nDTc8SxInZ5wxwcScxSicfvC9S73OSg=="
49+
50+
if quiet {
51+
err = selfupdate.Run(updInfo, pubKey, nil)
52+
} else {
53+
err = selfupdate.Run(updInfo, pubKey, interactive.Dispatcher())
54+
}
55+
56+
if err != nil {
57+
return 1
58+
}
59+
60+
return 0
61+
}
62+
63+
// ////////////////////////////////////////////////////////////////////////////////// //

cli/without_selfupdate.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build !selfupdate
2+
// +build !selfupdate
3+
4+
package cli
5+
6+
// ////////////////////////////////////////////////////////////////////////////////// //
7+
// //
8+
// Copyright (c) 2025 ESSENTIAL KAOS //
9+
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
10+
// //
11+
// ////////////////////////////////////////////////////////////////////////////////// //
12+
13+
var withSelfUpdate = false
14+
15+
// ////////////////////////////////////////////////////////////////////////////////// //
16+
17+
// updateBinary updates current binary to the latest version
18+
func updateBinary() int {
19+
return 1
20+
}
21+
22+
// ////////////////////////////////////////////////////////////////////////////////// //

common/lj.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Summary: Tool for viewing JSON logs
88
Name: lj
9-
Version: 0.2.1
9+
Version: 0.3.0
1010
Release: 0%{?dist}
1111
Group: Applications/System
1212
License: Apache License, Version 2.0
@@ -97,6 +97,11 @@ fi
9797
################################################################################
9898

9999
%changelog
100+
* Tue Jun 17 2025 Anton Novojilov <andy@essentialkaos.com> - 0.3.0-0
101+
- Fixed bug with parsing float numbers for filters
102+
- Code refactoring
103+
- Dependencies update
104+
100105
* Fri Apr 11 2025 Anton Novojilov <andy@essentialkaos.com> - 0.2.1-0
101106
- Use pager by default
102107
- Improved formatting in no color mode

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
module github.com/essentialkaos/lj
22

3-
go 1.23.7
3+
go 1.23.8
44

55
require (
6-
github.com/essentialkaos/ek/v13 v13.24.0
6+
github.com/essentialkaos/ek/v13 v13.30.1
77
github.com/tidwall/gjson v1.18.0
88
)
99

1010
require (
1111
github.com/essentialkaos/depsy v1.3.1 // indirect
1212
github.com/tidwall/match v1.1.1 // indirect
1313
github.com/tidwall/pretty v1.2.1 // indirect
14-
golang.org/x/sys v0.32.0 // indirect
14+
golang.org/x/sys v0.33.0 // indirect
1515
)

0 commit comments

Comments
 (0)