diff --git a/cli/cli.go b/cli/cli.go index d9773a0..3336e0c 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -15,14 +15,14 @@ import ( "github.com/essentialkaos/ek/v12/fmtc" "github.com/essentialkaos/ek/v12/options" + "github.com/essentialkaos/ek/v12/support" + "github.com/essentialkaos/ek/v12/support/deps" "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/usage" "github.com/essentialkaos/ek/v12/usage/completion/bash" "github.com/essentialkaos/ek/v12/usage/completion/fish" "github.com/essentialkaos/ek/v12/usage/completion/zsh" "github.com/essentialkaos/ek/v12/usage/man" - - "github.com/essentialkaos/path/cli/support" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -30,7 +30,7 @@ import ( // Basic utility info const ( APP = "path" - VER = "1.0.0" + VER = "1.0.1" DESC = "Dead simple tool for working with paths" ) @@ -122,7 +122,10 @@ func Run(gitRev string, gomod []byte) { genAbout(gitRev).Print(options.GetS(OPT_VER)) os.Exit(0) case options.GetB(OPT_VERB_VER): - support.Print(APP, VER, gitRev, gomod) + support.Collect(APP, VER). + WithRevision(gitRev). + WithDeps(deps.Extract(gomod)). + Print() os.Exit(0) case options.GetB(OPT_HELP) || len(args) == 0: genUsage().Print() diff --git a/cli/support/support.go b/cli/support/support.go deleted file mode 100644 index 588ea54..0000000 --- a/cli/support/support.go +++ /dev/null @@ -1,189 +0,0 @@ -package support - -// ////////////////////////////////////////////////////////////////////////////////// // -// // -// Copyright (c) 2024 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) - } -} - -// ////////////////////////////////////////////////////////////////////////////////// // diff --git a/common/path.spec b/common/path.spec index 359d558..f7aed90 100644 --- a/common/path.spec +++ b/common/path.spec @@ -10,7 +10,7 @@ Summary: Dead simple tool for working with paths Name: path -Version: 1.0.0 +Version: 1.0.1 Release: 0%{?dist} Group: Applications/System License: Apache License, Version 2.0 @@ -101,6 +101,11 @@ fi ################################################################################ %changelog +* Thu Mar 28 2024 Anton Novojilov - 1.0.1-0 +- Improved support information gathering +- Code refactoring +- Dependencies update + * Sun Feb 18 2024 Anton Novojilov - 1.0.0-0 - Added dirn command - Code refactoring diff --git a/go.mod b/go.mod index 16bd938..94c5317 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/essentialkaos/path go 1.18 +require github.com/essentialkaos/ek/v12 v12.113.1 + require ( - github.com/essentialkaos/depsy v1.1.0 - github.com/essentialkaos/ek/v12 v12.104.0 + github.com/essentialkaos/depsy v1.1.0 // indirect + golang.org/x/sys v0.18.0 // indirect ) - -require golang.org/x/sys v0.18.0 // indirect diff --git a/go.sum b/go.sum index 39a4f76..efceef3 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ 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.104.0 h1:srNIOipfcfqwWoiZKjIuRhbvEBt0UyP5ni13bimU1Iw= -github.com/essentialkaos/ek/v12 v12.104.0/go.mod h1:exBTL3OE3dm4vjHihE4ZhQ3onJq7C8q2r+OTZmpCO6s= +github.com/essentialkaos/ek/v12 v12.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg= +github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U= 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=