Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Feb 17, 2024
1 parent 7fe70e6 commit e00cac1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 36 deletions.
46 changes: 24 additions & 22 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -71,6 +72,8 @@ var optMap = options.Map{
OPT_GENERATE_MAN: {Type: options.BOOL},
}

var colorTagApp, colorTagVer string

// ////////////////////////////////////////////////////////////////////////////////// //

// Run is main utility function
Expand Down Expand Up @@ -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}"
}
}

Expand Down Expand Up @@ -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")
Expand All @@ -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 <https://www.apache.org/licenses/LICENSE-2.0>",
UpdateChecker: usage.UpdateChecker{"essentialkaos/bop", update.GitHubChecker},
}
Expand Down
20 changes: 19 additions & 1 deletion cli/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"
"runtime"
"runtime/debug"
"strings"

"github.com/essentialkaos/ek/v12/fmtc"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 == "" {
Expand Down
23 changes: 12 additions & 11 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ 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
}

// 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 ""
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit e00cac1

Please sign in to comment.