diff --git a/cli/cli.go b/cli/cli.go index f0bc9fc..e4ac080 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -19,6 +19,7 @@ import ( "github.com/essentialkaos/ek/v12/fsutil" "github.com/essentialkaos/ek/v12/options" "github.com/essentialkaos/ek/v12/pluralize" + "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/timeutil" "github.com/essentialkaos/ek/v12/usage" "github.com/essentialkaos/ek/v12/usage/completion/bash" @@ -38,7 +39,7 @@ import ( // App info const ( APP = "bop" - VER = "1.2.2" + VER = "1.3.0" DESC = "Utility for generating formal bibop tests for RPM packages" ) @@ -71,6 +72,8 @@ var optMap = options.Map{ OPT_GENERATE_MAN: {Type: options.BOOL}, } +var colorTagApp, colorTagVer string + // ////////////////////////////////////////////////////////////////////////////////// // // Run is main utility function @@ -113,25 +116,17 @@ func Run(gitRev string, gomod []byte) { // preConfigureUI preconfigures UI based on information about user terminal func preConfigureUI() { - term := os.Getenv("TERM") - - fmtc.DisableColors = true - - if term != "" { - switch { - case strings.Contains(term, "xterm"), - strings.Contains(term, "color"), - term == "screen": - fmtc.DisableColors = false - } - } - - if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" { + if !tty.IsTTY() { fmtc.DisableColors = true } - if os.Getenv("NO_COLOR") != "" { - fmtc.DisableColors = true + switch { + case fmtc.IsTrueColorSupported(): + colorTagApp, colorTagVer = "{*}{#9966CC}", "{#9966CC}" + case fmtc.Is256ColorsSupported(): + colorTagApp, colorTagVer = "{*}{#140}", "{#140}" + default: + colorTagApp, colorTagVer = "{*}{m}", "{m}" } } @@ -269,6 +264,8 @@ func printMan() { func genUsage() *usage.Info { info := usage.NewInfo("", "name", "package…") + info.AppNameColorTag = colorTagApp + info.AddOption(OPT_OUTPUT, "Output file", "file") info.AddOption(OPT_SERVICE, "List of services for checking {c}(mergeable){!}", "service") info.AddOption(OPT_NO_COLOR, "Disable colors in output") @@ -285,11 +282,16 @@ func genUsage() *usage.Info { // genAbout generates info about version func genAbout(gitRev string) *usage.About { about := &usage.About{ - App: APP, - Version: VER, - Desc: DESC, - Year: 2006, - Owner: "ESSENTIAL KAOS", + App: APP, + Version: VER, + Desc: DESC, + Year: 2006, + Owner: "ESSENTIAL KAOS", + + AppNameColorTag: colorTagApp, + VersionColorTag: colorTagVer, + DescSeparator: "{s}—{!}", + License: "Apache License, Version 2.0 ", UpdateChecker: usage.UpdateChecker{"essentialkaos/bop", update.GitHubChecker}, } diff --git a/cli/support/support.go b/cli/support/support.go index e6bc109..83982d1 100644 --- a/cli/support/support.go +++ b/cli/support/support.go @@ -11,6 +11,7 @@ import ( "fmt" "os" "runtime" + "runtime/debug" "strings" "github.com/essentialkaos/ek/v12/fmtc" @@ -107,6 +108,23 @@ func showDepsInfo(gomod []byte) { } } +// 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 { @@ -118,7 +136,7 @@ func getHashColorBullet(v string) string { // printInfo formats and prints info record func printInfo(size int, name, value string) { - name = name + ":" + name += ":" size++ if value == "" { diff --git a/data/data.go b/data/data.go index 7ffaec9..32e6f0a 100644 --- a/data/data.go +++ b/data/data.go @@ -15,17 +15,18 @@ import ( // Info contains info about all packages type Info struct { - Dist string - Pkgs []string - Apps []string - Configs []*rpm.Object - SharedLibs []string - StaticLibs []*rpm.Object - Headers []string - PkgConfigs []string - Users UserMap - Groups GroupMap - Services []string + Dist string + Pkgs []string + Apps []string + Configs []*rpm.Object + SharedLibs []string + StaticLibs []*rpm.Object + Headers []string + PkgConfigs []string + Completions []string + Users UserMap + Groups GroupMap + Services []string Python2Dirs []*rpm.Object Python2Files []*rpm.Object diff --git a/extractor/extractor.go b/extractor/extractor.go index 092b54b..4674bfc 100644 --- a/extractor/extractor.go +++ b/extractor/extractor.go @@ -111,6 +111,7 @@ func addPackageInfo(info *data.Info, pkg *rpm.Package) { addAppsInfo(info, pkg) addConfigsInfo(info, pkg) + addCompletions(info, pkg) addLibsInfo(info, pkg) addHeadersInfo(info, pkg) addPkgConfigsInfo(info, pkg) @@ -166,6 +167,20 @@ func addConfigsInfo(info *data.Info, pkg *rpm.Package) { } } +// addCompletions extracts info about shell completions +func addCompletions(info *data.Info, pkg *rpm.Package) { + for _, obj := range pkg.Payload { + if strutil.HasPrefixAny( + obj.Path, + "/usr/share/bash-completion/completions", + "/usr/share/fish/vendor_completions.d", + "/usr/share/zsh/site-functions", + ) { + info.Completions = append(info.Completions, obj.Path) + } + } +} + // addPkgConfigsInfo extracts info about package configuration files // from package info func addPkgConfigsInfo(info *data.Info, pkg *rpm.Package) { diff --git a/generator/generator.go b/generator/generator.go index 7d3286d..885db2f 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -293,7 +293,7 @@ func genPythonWheelsCheck(info *data.Info) string { for _, wheel := range info.PythonWheels { data += fmt.Sprintf(" exist %s\n", wheel.Path) - data += fmt.Sprintf(" perms %s %o\n\n", wheel.Path, wheel.Mode) + data += fmt.Sprintf(" mode %s %o\n\n", wheel.Path, wheel.Mode) } return data @@ -301,7 +301,7 @@ func genPythonWheelsCheck(info *data.Info) string { // genBasicEnvCheck generates env checks for very simple package func genBasicEnvCheck(info *data.Info) string { - if len(info.Apps) == 0 && len(info.Services) == 0 && len(info.Configs) == 0 { + if len(info.Apps)+len(info.Completions)+len(info.Services)+len(info.Configs) == 0 { return "" } @@ -332,6 +332,15 @@ func genBasicEnvCheck(info *data.Info) string { data += "\n" } + if len(info.Completions) > 0 { + for _, compl := range info.Completions { + data += fmt.Sprintf(" exist %s\n", compl) + data += fmt.Sprintf(" mode %s 644\n", compl) + } + + data += "\n" + } + return data }