Skip to content

Commit

Permalink
Merge pull request #128 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 7.0.0
  • Loading branch information
andyone authored Mar 21, 2023
2 parents e876a90 + cbe20aa commit 4aa2648
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}

Expand Down Expand Up @@ -84,7 +84,7 @@ jobs:

steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: '1.19.x'

Expand Down
4 changes: 2 additions & 2 deletions COOKBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ Also, there are some run-time variables:
| Name | Description |
|------|-------------|
| `ENV:*` | Environment variable (_see example below_) |
| `DATE:*` | Current date with given [format](https://pkg.go.dev/github.com/essentialkaos/ek/v12/timeutil#Format) (_see example below_) |
| `WORKDIR` | Path to working directory |
| `TIMESTAMP` | Unix timestamp |
| `DATE` | Current date |
| `HOSTNAME` | Hostname |
| `IP` | Host IP |
| `OS` | OS name (_linux/darwin/freebsd…_) |
Expand Down Expand Up @@ -444,7 +444,7 @@ command "-" "Check shared library"
var app_name mysuppaapp
command "go build {app_name}.go" "Build application"
exist {ENV:GOPATH}/bin/{app_name}
exist {ENV:GOPATH}/bin/{app_name}_{DATE:%Y%m%d}
```

Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Information about bibop recipe syntax you can find in our [cookbook](COOKBOOK.md

#### From source

To build the `bibop` from scratch, make sure you have a working Go 1.17+ workspace ([instructions](https://golang.org/doc/install)), then:
To build the `bibop` from scratch, make sure you have a working Go 1.18+ workspace ([instructions](https://golang.org/doc/install)), then:

```
go install github.com/essentialkaos/bibop@latest
Expand All @@ -43,7 +43,7 @@ bash <(curl -fsSL https://apps.kaos.st/get) bibop

### Docker support

Official webkaos images available on [Docker Hub](http://kaos.sh/d/bibop) and [GitHub Container Registry](https://kaos.sh/p/bibop). Install the latest version of Docker, then:
Official webkaos images available on [GitHub Container Registry](https://kaos.sh/p/bibop) and [Docker Hub](http://kaos.sh/d/bibop). Install the latest version of Docker, then:

```bash
curl -fL# -o bibop-docker https://kaos.sh/bibop/bibop-docker
Expand All @@ -52,8 +52,6 @@ sudo mv bibop-docker /usr/bin/

bibop-docker your.recipe your-package.rpm
# or
bibop-docker --image essentialkaos/bibop:centos7 your.recipe your-package.rpm
# or
bibop-docker --image ghcr.io/essentialkaos/bibop:centos7 your.recipe your-package.rpm
```

Expand Down
2 changes: 1 addition & 1 deletion bibop.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ var gitrev string
// ////////////////////////////////////////////////////////////////////////////////// //

func main() {
CLI.Init(gitrev, gomod)
CLI.Run(gitrev, gomod)
}
83 changes: 46 additions & 37 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ import (
"github.com/essentialkaos/ek/v12/usage/update"

"github.com/essentialkaos/bibop/cli/executor"
"github.com/essentialkaos/bibop/cli/support"
"github.com/essentialkaos/bibop/parser"
"github.com/essentialkaos/bibop/recipe"
"github.com/essentialkaos/bibop/render"
"github.com/essentialkaos/bibop/support"
)

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

// Application info
const (
APP = "bibop"
VER = "6.3.0"
VER = "7.0.0"
DESC = "Utility for testing command-line tools"
)

Expand Down Expand Up @@ -84,8 +84,8 @@ var optMap = options.Map{
OPT_INGORE_PACKAGES: {Type: options.BOOL},
OPT_NO_CLEANUP: {Type: options.BOOL},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL, Alias: "u:usage"},
OPT_VER: {Type: options.BOOL, Alias: "ver"},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.BOOL},

OPT_VERB_VER: {Type: options.BOOL},
OPT_COMPLETION: {},
Expand All @@ -98,33 +98,33 @@ var rawOutput bool

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

func Init(gitRev string, gomod []byte) {
func Run(gitRev string, gomod []byte) {
preConfigureUI()

args, errs := options.Parse(optMap)

if len(errs) != 0 {
for _, err := range errs {
printError(err.Error())
}

printError(errs[0].Error())
os.Exit(1)
}

configureUI()

switch {
case options.Has(OPT_COMPLETION):
os.Exit(genCompletion())
os.Exit(printCompletion())
case options.Has(OPT_GENERATE_MAN):
os.Exit(genMan())
printMan()
os.Exit(0)
case options.GetB(OPT_VER):
showAbout(gitRev)
return
genAbout(gitRev).Print()
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.ShowSupportInfo(APP, VER, gitRev, gomod)
return
support.Print(APP, VER, gitRev, gomod)
os.Exit(0)
case options.GetB(OPT_HELP) || len(args) == 0:
showUsage()
return
genUsage().Print()
os.Exit(0)
}

configureSubsystems()
Expand All @@ -133,6 +133,31 @@ func Init(gitRev string, gomod []byte) {
process(args.Get(0).Clean().String())
}

// 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") == "" {
fmtc.DisableColors = true
rawOutput = true
}

if os.Getenv("NO_COLOR") != "" {
fmtc.DisableColors = true
}
}

// configureUI configure user interface
func configureUI() {
if options.GetB(OPT_NO_COLOR) {
Expand All @@ -155,10 +180,6 @@ func configureUI() {
}

fmtutil.SeparatorTitleColorTag = colorTagApp

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
rawOutput = true
}
}

// configureSubsystems configures bibop subsystems
Expand Down Expand Up @@ -388,18 +409,8 @@ func printErrorAndExit(f string, a ...interface{}) {

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

// showUsage prints usage info
func showUsage() {
genUsage().Render()
}

// showAbout prints info about version
func showAbout(gitRev string) {
genAbout(gitRev).Render()
}

// genCompletion generates completion for different shells
func genCompletion() int {
// printCompletion prints completion for given shell
func printCompletion() int {
info := genUsage()

switch options.GetS(OPT_COMPLETION) {
Expand All @@ -416,16 +427,14 @@ func genCompletion() int {
return 0
}

// genMan generates man page
func genMan() int {
// printMan prints man page
func printMan() {
fmt.Println(
man.Generate(
genUsage(),
genAbout(""),
),
)

return 0
}

// genUsage generates usage info
Expand Down
4 changes: 2 additions & 2 deletions support/support.go → cli/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type Pkgs []Pkg

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

// ShowSupportInfo prints verbose info about application, system, dependencies and
// Print prints verbose info about application, system, dependencies and
// important environment
func ShowSupportInfo(app, ver, gitRev string, gomod []byte) {
func Print(app, ver, gitRev string, gomod []byte) {
pkgs := collectEnvInfo()

fmtutil.SeparatorTitleColorTag = "{s-}"
Expand Down
File renamed without changes.
35 changes: 23 additions & 12 deletions support/support_linux.go → cli/support/support_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/essentialkaos/ek/v12/fmtutil"
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/system"
"github.com/essentialkaos/ek/v12/system/container"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -53,10 +52,10 @@ func showOSInfo() {

containerEngine := "No"

switch systemInfo.ContainerEngine {
case container.DOCKER:
switch {
case fsutil.IsExist("/.dockerenv"):
containerEngine = "Yes (Docker)"
case container.PODMAN:
case fsutil.IsExist("/run/.containerenv"):
containerEngine = "Yes (Podman)"
}

Expand Down Expand Up @@ -105,16 +104,28 @@ func collectEnvInfo() Pkgs {
}
}

// getPackageVersion returns package name from rpm database
func getPackageInfo(name string) Pkg {
switch {
case isDEBBased():
return getDEBPackageInfo(name)
case isRPMBased():
return getRPMPackageInfo(name)
// getPackageVersion returns package name and version from package manager database
func getPackageInfo(names ...string) Pkg {
var info Pkg

if len(names) == 0 {
return Pkg{}
}

for _, name := range names {
switch {
case isDEBBased():
info = getDEBPackageInfo(name)
case isRPMBased():
info = getRPMPackageInfo(name)
}

if info.Version != "" {
return info
}
}

return Pkg{name, ""}
return Pkg{names[0], ""}
}

// isDEBBased returns true if is DEB-based distro
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/essentialkaos/bibop

go 1.17
go 1.18

require (
github.com/buger/jsonparser v1.1.1
github.com/essentialkaos/check v1.3.0
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/depsy v1.0.0
github.com/essentialkaos/ek/v12 v12.60.0
github.com/essentialkaos/ek/v12 v12.63.0
github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2
)

require (
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/sys v0.5.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
)
Loading

0 comments on commit 4aa2648

Please sign in to comment.