diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10ea1ab..9ec46f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: strategy: matrix: - go: [ '1.20.x', '1.21.x' ] + go: [ '1.21.x', '1.22.x' ] steps: - name: Checkout diff --git a/README.md b/README.md index 4710d3e..59f307a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ #### From sources -To build the `deadline` from scratch, make sure you have a working Go 1.19+ workspace (_[instructions](https://go.dev/doc/install)_), then: +To build the `deadline` from scratch, make sure you have a working Go 1.21+ workspace (_[instructions](https://go.dev/doc/install)_), then: ``` go install github.com/essentialkaos/deadline@latest diff --git a/cli/cli.go b/cli/cli.go index b009011..f1bb542 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -2,7 +2,7 @@ package cli // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // @@ -21,19 +21,20 @@ import ( "github.com/essentialkaos/ek/v12/fmtc" "github.com/essentialkaos/ek/v12/fsutil" "github.com/essentialkaos/ek/v12/strutil" + "github.com/essentialkaos/ek/v12/support" + "github.com/essentialkaos/ek/v12/support/deps" "github.com/essentialkaos/ek/v12/system/process" + "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/timeutil" "github.com/essentialkaos/ek/v12/usage" - - "github.com/essentialkaos/deadline/support" ) // ////////////////////////////////////////////////////////////////////////////////// // const ( APP = "deadline" - VER = "1.6.0" + VER = "1.6.1" DESC = "Simple utility for controlling application working time" ) @@ -45,7 +46,7 @@ const ( ) // ERROR_EXIT_CODE is exit code used as error marker -const ERROR_EXIT_CODE = 99 +const ERROR_EXIT_CODE = 255 // ////////////////////////////////////////////////////////////////////////////////// // @@ -56,6 +57,7 @@ type SignalInfo struct { // ////////////////////////////////////////////////////////////////////////////////// // +// cmd is passed command var cmd *exec.Cmd // colorTagApp contains color tag for app name @@ -81,7 +83,10 @@ func Run(gitRev string, gomod []byte) { genAbout(gitRev).Print() return case "-vv", "--verbose-version": - support.Print(APP, VER, gitRev, gomod) + support.Collect(APP, VER). + WithRevision(gitRev). + WithDeps(deps.Extract(gomod)). + Print() return } } @@ -140,7 +145,7 @@ func parseArgs(args []string) (SignalInfo, string, []string) { sigInfo, err = parseTimeAndSignal(args[1]) if err != nil { - printError(err.Error()) + terminal.Error(err) os.Exit(ERROR_EXIT_CODE) } @@ -151,7 +156,7 @@ func parseArgs(args []string) (SignalInfo, string, []string) { } if !fsutil.CheckPerms("FX", cmdApp) { - printError("Can't execute command %q", args[2]) + terminal.Error("Can't execute command %q", args[2]) os.Exit(ERROR_EXIT_CODE) } @@ -241,13 +246,13 @@ func parseTimeAndSignal(data string) (SignalInfo, error) { return SignalInfo{wait, syscall.SIGTERM}, nil } - wait, err = timeutil.ParseDuration(strutil.ReadField(data, 0, true, ":")) + wait, err = timeutil.ParseDuration(strutil.ReadField(data, 0, true, ':')) if err != nil { return SignalInfo{}, fmt.Errorf("Can't parse %q", data) } - signal := strutil.ReadField(data, 1, true, ":") + signal := strutil.ReadField(data, 1, true, ':') switch strings.ToUpper(signal) { case "SIGABRT", "ABRT", "6": @@ -319,16 +324,6 @@ func parseTimeAndSignal(data string) (SignalInfo, error) { return SignalInfo{wait, sig}, nil } -// printError prints error message to stderr -func printError(message string, args ...interface{}) { - switch len(args) { - case 0: - fmt.Fprintf(os.Stderr, "%s\n", message) - case 1: - fmt.Fprintf(os.Stderr, "%s\n", fmt.Sprintf(message, args...)) - } -} - // ////////////////////////////////////////////////////////////////////////////////// // // genUsage generates usage info @@ -367,5 +362,9 @@ func genAbout(gitRev string) *usage.About { License: "Apache License, Version 2.0 ", } + if gitRev != "" { + about.Build = "git:" + gitRev + } + return about } diff --git a/common/deadline.spec b/common/deadline.spec index 7647912..e1cabb2 100644 --- a/common/deadline.spec +++ b/common/deadline.spec @@ -6,7 +6,7 @@ Summary: Simple utility for controlling application working time Name: deadline -Version: 1.6.0 +Version: 1.6.1 Release: 0%{?dist} Group: Applications/System License: Apache 2.0 @@ -16,7 +16,7 @@ Source0: https://source.kaos.st/%{name}/%{name}-%{version}.tar.bz2 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -BuildRequires: golang >= 1.20 +BuildRequires: golang >= 1.21 Provides: %{name} = %{version}-%{release} @@ -60,6 +60,11 @@ rm -rf %{buildroot} ################################################################################ %changelog +* Fri May 03 2024 Anton Novojilov - 1.6.1-0 +- Improved support information gathering +- Code refactoring +- Dependencies update + * Thu Jan 11 2024 Anton Novojilov - 1.6.0-0 - Code refactoring - Dependencies update diff --git a/deadline.go b/deadline.go index 2e62beb..f960e72 100644 --- a/deadline.go +++ b/deadline.go @@ -5,7 +5,7 @@ package main // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2023 ESSENTIAL KAOS // +// Copyright (c) 2024 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/go.mod b/go.mod index f5fb760..45f6500 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/essentialkaos/deadline go 1.18 require ( - github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.93.0 + github.com/essentialkaos/depsy v1.3.0 + github.com/essentialkaos/ek/v12 v12.121.0 ) -require golang.org/x/sys v0.16.0 // indirect +require golang.org/x/sys v0.19.0 // indirect diff --git a/go.sum b/go.sum index fe9988c..6ddc076 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= -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.93.0 h1:5lwuNYgUYjQHy2h57adWt2t1w5L2MxqTPKgHjyH3h6k= -github.com/essentialkaos/ek/v12 v12.93.0/go.mod h1:peB5w8zUkRuDs7m/QG5Z2gMmqzSIs2viAmxzzNFIIoo= +github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= +github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= +github.com/essentialkaos/ek/v12 v12.121.0 h1:Ax/6FsF6mYzT9KSaphqGqrphvMuWslSCIUCrQqWk0v0= +github.com/essentialkaos/ek/v12 v12.121.0/go.mod h1:VUiC4T8afqtE+UzJftTlIypDBKI1s+0nxxNfBhjyIbo= 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.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/support/support.go b/support/support.go deleted file mode 100644 index 74070a5..0000000 --- a/support/support.go +++ /dev/null @@ -1,189 +0,0 @@ -package support - -// ////////////////////////////////////////////////////////////////////////////////// // -// // -// Copyright (c) 2023 ESSENTIAL KAOS // -// Apache License, Version 2.0 // -// // -// ////////////////////////////////////////////////////////////////////////////////// // - -import ( - "fmt" - "os" - "runtime" - "runtime/debug" - "strings" - - "github.com/essentialkaos/ek/v12/fmtc" - "github.com/essentialkaos/ek/v12/fmtutil" - "github.com/essentialkaos/ek/v12/hash" - "github.com/essentialkaos/ek/v12/strutil" - "github.com/essentialkaos/ek/v12/system" - "github.com/essentialkaos/ek/v12/system/container" - - "github.com/essentialkaos/depsy" -) - -// ////////////////////////////////////////////////////////////////////////////////// // - -// Print prints verbose info about application, system, dependencies and -// important environment -func Print(app, ver, gitRev string, gomod []byte) { - fmtutil.SeparatorTitleColorTag = "{s-}" - fmtutil.SeparatorFullscreen = false - fmtutil.SeparatorColorTag = "{s-}" - fmtutil.SeparatorSize = 80 - - showApplicationInfo(app, ver, gitRev) - showOSInfo() - showDepsInfo(gomod) - - fmtutil.Separator(false) -} - -// ////////////////////////////////////////////////////////////////////////////////// // - -// showApplicationInfo shows verbose information about application -func showApplicationInfo(app, ver, gitRev string) { - fmtutil.Separator(false, "APPLICATION INFO") - - printInfo(7, "Name", app) - printInfo(7, "Version", ver) - - printInfo(7, "Go", fmtc.Sprintf( - "%s {s}(%s/%s){!}", - strings.TrimLeft(runtime.Version(), "go"), - runtime.GOOS, runtime.GOARCH, - )) - - if gitRev == "" { - gitRev = extractGitRevFromBuildInfo() - } - - if gitRev != "" { - if !fmtc.DisableColors && fmtc.IsTrueColorSupported() { - printInfo(7, "Git SHA", gitRev+getHashColorBullet(gitRev)) - } else { - printInfo(7, "Git SHA", gitRev) - } - } - - bin, _ := os.Executable() - binSHA := hash.FileHash(bin) - - if binSHA != "" { - binSHA = strutil.Head(binSHA, 7) - if !fmtc.DisableColors && fmtc.IsTrueColorSupported() { - printInfo(7, "Bin SHA", binSHA+getHashColorBullet(binSHA)) - } else { - printInfo(7, "Bin SHA", binSHA) - } - } -} - -// showOSInfo shows verbose information about system -func showOSInfo() { - osInfo, err := system.GetOSInfo() - - if err == nil { - fmtutil.Separator(false, "OS INFO") - - printInfo(12, "Name", osInfo.ColoredName()) - printInfo(12, "Pretty Name", osInfo.ColoredPrettyName()) - printInfo(12, "Version", osInfo.Version) - printInfo(12, "ID", osInfo.ID) - printInfo(12, "ID Like", osInfo.IDLike) - printInfo(12, "Version ID", osInfo.VersionID) - printInfo(12, "Version Code", osInfo.VersionCodename) - printInfo(12, "Platform ID", osInfo.PlatformID) - printInfo(12, "CPE", osInfo.CPEName) - } - - systemInfo, err := system.GetSystemInfo() - - if err != nil { - return - } else if osInfo == nil { - fmtutil.Separator(false, "SYSTEM INFO") - printInfo(12, "Name", systemInfo.OS) - } - - printInfo(12, "Arch", systemInfo.Arch) - printInfo(12, "Kernel", systemInfo.Kernel) - - containerEngine := "No" - - switch container.GetEngine() { - case container.DOCKER: - containerEngine = "Yes (Docker)" - case container.PODMAN: - containerEngine = "Yes (Podman)" - case container.LXC: - containerEngine = "Yes (LXC)" - } - - fmtc.NewLine() - - printInfo(12, "Container", containerEngine) -} - -// showDepsInfo shows information about all dependencies -func showDepsInfo(gomod []byte) { - deps := depsy.Extract(gomod, false) - - if len(deps) == 0 { - return - } - - fmtutil.Separator(false, "DEPENDENCIES") - - for _, dep := range deps { - if dep.Extra == "" { - fmtc.Printf(" {s}%8s{!} %s\n", dep.Version, dep.Path) - } else { - fmtc.Printf(" {s}%8s{!} %s {s-}(%s){!}\n", dep.Version, dep.Path, dep.Extra) - } - } -} - -// extractGitRevFromBuildInfo extracts git SHA from embedded build info -func extractGitRevFromBuildInfo() string { - info, ok := debug.ReadBuildInfo() - - if !ok { - return "" - } - - for _, s := range info.Settings { - if s.Key == "vcs.revision" && len(s.Value) > 7 { - return s.Value[:7] - } - } - - return "" -} - -// getHashColorBullet return bullet with color from hash -func getHashColorBullet(v string) string { - if len(v) > 6 { - v = strutil.Head(v, 6) - } - - return fmtc.Sprintf(" {#" + strutil.Head(v, 6) + "}● {!}") -} - -// printInfo formats and prints info record -func printInfo(size int, name, value string) { - name += ":" - size++ - - if value == "" { - fm := fmt.Sprintf(" {*}%%-%ds{!} {s-}—{!}\n", size) - fmtc.Printf(fm, name) - } else { - fm := fmt.Sprintf(" {*}%%-%ds{!} %%s\n", size) - fmtc.Printf(fm, name, value) - } -} - -// ////////////////////////////////////////////////////////////////////////////////// //