Skip to content

Commit

Permalink
Merge pull request #62 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 1.2.2
  • Loading branch information
andyone authored Mar 23, 2023
2 parents 2397a1e + 1b10724 commit d2a5fe3
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 100 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,38 @@ on:
branches: [master]
schedule:
- cron: '30 12 */15 * *'
workflow_dispatch:
inputs:
force_run:
description: 'Force workflow run'
required: true
type: choice
options: [yes, no]

permissions:
actions: read
contents: read
statuses: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
SRC_DIR: src/github.com/${{ github.repository }}

jobs:
Go:
name: Go
runs-on: ubuntu-latest

env:
SRC_DIR: src/github.com/${{ github.repository }}

strategy:
matrix:
go: [ '1.19.x', '1.20.x' ]

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

Expand All @@ -49,13 +61,9 @@ jobs:

needs: Go

env:
SRC_DIR: src/github.com/${{ github.repository }}
GO111MODULE: auto

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

Expand Down Expand Up @@ -87,7 +95,7 @@ jobs:
- name: Check scripts with Shellcheck
uses: essentialkaos/shellcheck-action@v1
with:
files: bop-docker
files: bop-container

Hadolint:
name: Hadolint
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 2.1.0 using next command:
# This Makefile generated by GoMakeGen 2.2.0 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen
Expand Down Expand Up @@ -94,6 +94,6 @@ help: ## Show this info
| sed 's/ifdef //' \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 2.1.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 2.2.0\033[0m\n'

################################################################################
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="#license"><img src="https://gh.kaos.st/apache2.svg"></a>
</p>

<p align="center"><a href="#installation">Installation</a> • <a href="#docker-support">Docker support</a> • <a href="#command-line-completion">Command-line completion</a> • <a href="#man-documentation">Man documentation</a> • <a href="#usage">Usage</a> • <a href="#build-status">Build Status</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a></p>
<p align="center"><a href="#installation">Installation</a> • <a href="#command-line-completion">Command-line completion</a> • <a href="#man-documentation">Man documentation</a> • <a href="#usage">Usage</a> • <a href="#build-status">Build Status</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a></p>

</br>

Expand All @@ -20,8 +20,8 @@

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

```
go install github.com/essentialkaos/bop
```bash
go install github.com/essentialkaos/bop@latest
```

#### Prebuilt binaries
Expand All @@ -32,35 +32,35 @@ You can download prebuilt binaries for Linux from [EK Apps Repository](https://a
bash <(curl -fsSL https://apps.kaos.st/get) bop
```

### Docker support
#### Container image

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

```bash
curl -#L -o bop-docker https://kaos.sh/bop/bop-docker
chmod +x bop-docker
sudo mv bop-docker /usr/bin/
bop-docker test-name package.rpm
curl -#L -o bop-container https://kaos.sh/bop/bop-container
chmod +x bop-container
sudo mv bop-container /usr/bin/bop
bop test-name package.rpm
```

### Command-line completion

You can generate completion for `bash`, `zsh` or `fish` shell.

Bash:
```
```bash
sudo bop --completion=bash 1> /etc/bash_completion.d/bop
```


ZSH:
```
```bash
sudo bop --completion=zsh 1> /usr/share/zsh/site-functions/bop
```


Fish:
```
```bash
sudo bop --completion=fish 1> /usr/share/fish/vendor_completions.d/bop.fish
```

Expand Down
24 changes: 22 additions & 2 deletions bop-docker → bop-container
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ BOP_IMAGE="${IMAGE:-$IMAGE_GH}"

################################################################################

engine=""

################################################################################

# Main func
#
# *: All unparsed arguments passed to the script
#
# Code: No
# Echo: No
main() {
if ! hasApp "docker" ; then
engine=$(getContainerEngine)

if [[ -z "$engine" ]] ; then
error "You must install Docker first"
exit 1
fi
Expand All @@ -72,11 +78,25 @@ run() {
cwd=$(pwd)

# shellcheck disable=SC2086,SC2048
docker run --rm -it -v "${cwd}:/bop" "$BOP_IMAGE" $*
$engine run --rm -it -v "${cwd}:/bop" "$BOP_IMAGE" $*

return $?
}

# Get used container engine
#
# Code: No
# Echo: Engine name (String)
getContainerEngine() {
if hasApp "docker" ; then
echo "docker"
fi

if hasApp "podman" ; then
echo "podman"
fi
}

# Checks if given app is installed
#
# 1: Binray name (String)
Expand Down
2 changes: 1 addition & 1 deletion bop.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)
}
79 changes: 48 additions & 31 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
// App info
const (
APP = "bop"
VER = "1.2.1"
VER = "1.2.2"
DESC = "Utility for generating formal bibop tests for RPM packages"
)

Expand Down Expand Up @@ -73,35 +73,33 @@ var optMap = options.Map{

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

// Init is main function
func Init(gitRev string, gomod []byte) {
// Run is main utility function
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)
}

if options.GetB(OPT_NO_COLOR) {
fmtc.DisableColors = true
}
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)
genAbout(gitRev).Print()
os.Exit(0)
case options.GetB(OPT_VERB_VER):
support.ShowSupportInfo(APP, VER, gitRev, gomod)
support.Print(APP, VER, gitRev, gomod)
os.Exit(0)
case options.GetB(OPT_HELP) || len(args) < 2:
showUsage()
genUsage().Print()
os.Exit(0)
}

Expand All @@ -113,6 +111,37 @@ func Init(gitRev string, gomod []byte) {
processFiles(name, files)
}

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

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

// configureUI configures user interface
func configureUI() {
if options.GetB(OPT_NO_COLOR) {
fmtc.DisableColors = true
}
}

// checkSystem checks system
func checkSystem() {
if env.Which("rpm") == "" {
Expand Down Expand Up @@ -208,18 +237,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 @@ -236,16 +255,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 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
28 changes: 20 additions & 8 deletions cli/support/support_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,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
Loading

0 comments on commit d2a5fe3

Please sign in to comment.