Skip to content

Commit

Permalink
Merge pull request #91 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.1
  • Loading branch information
andyone authored Apr 1, 2024
2 parents 8902944 + 1fec29d commit ce49e7c
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 389 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ jobs:

strategy:
matrix:
go: [ '1.20.x' ]
go: [ '1.21.x', '1.22.x' ]

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

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

Expand All @@ -54,7 +54,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check spelling
continue-on-error: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: go

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor
rds-payload-generator
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#### From source

To build the RDS Payload Generator from scratch, make sure you have a working Go 1.20+ workspace ([instructions](https://go.dev/doc/install)), then:
To build the RDS Payload Generator from scratch, make sure you have a working Go 1.21+ workspace ([instructions](https://go.dev/doc/install)), then:

```
go install github.com/essentialkaos/rds-payload-generator@latest
Expand Down
89 changes: 61 additions & 28 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
"os/exec"
"strconv"
"strings"
"time"
Expand All @@ -19,26 +20,32 @@ import (
"github.com/essentialkaos/ek/v12/fsutil"
"github.com/essentialkaos/ek/v12/options"
"github.com/essentialkaos/ek/v12/rand"
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/support"
"github.com/essentialkaos/ek/v12/support/deps"
"github.com/essentialkaos/ek/v12/support/pkgs"
"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/ek/v12/usage/update"

"github.com/essentialkaos/redy/v4"

"github.com/essentialkaos/rds-payload-generator/cli/support"
)

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

// Application info
const (
APP = "RDS Payload Generator"
VER = "2.0.0"
VER = "2.0.1"
DESC = "Payload generator for RDS"
)

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

// Supported command line options
const (
OPT_DIR = "d:dir"
Expand Down Expand Up @@ -69,20 +76,27 @@ type RedisStore struct {

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

// optMap is map with supported options
var optMap = options.Map{
OPT_DIR: {},
OPT_KEYS: {Type: options.INT, Value: 5000, Min: 10, Max: 1000000},
OPT_RATIO: {Type: options.INT, Value: 4, Min: 1, Max: 100},
OPT_PAUSE: {Type: options.INT, Value: 15, Min: 1, Max: 1000},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.BOOL},
OPT_VER: {Type: options.MIXED},

OPT_VERB_VER: {Type: options.BOOL},
OPT_COMPLETION: {},
OPT_GENERATE_MAN: {Type: options.BOOL},
}

// colorTagApp contains color tag for app name
var colorTagApp string

// colorTagVer contains color tag for app version
var colorTagVer string

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

// Run is main utility function
Expand Down Expand Up @@ -111,7 +125,12 @@ func Run(gitRev string, gomod []byte) {
genAbout(gitRev).Print()
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)).
WithPackages(pkgs.Collect("rds", "rds-sync")).
WithApps(getRedisVersionInfo()).
Print()
os.Exit(0)
case options.GetB(OPT_HELP):
genUsage().Print()
Expand All @@ -124,28 +143,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
}
}

// Check for output redirect using pipes
if fsutil.IsCharacterDevice("/dev/stdin") &&
!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 = "{*}{#DC382C}", "{#A32422}"
case fmtc.Is256ColorsSupported():
colorTagApp, colorTagVer = "{*}{#160}", "{#124}"
default:
colorTagApp, colorTagVer = "{r*}", "{r}"
}
}

Expand Down Expand Up @@ -310,17 +318,32 @@ func (rs *RedisStore) Remove(id string) {

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

// getRedisVersionInfo returns info about Redis version
func getRedisVersionInfo() support.App {
cmd := exec.Command("redis-server", "--version")
output, err := cmd.Output()

if err != nil {
return support.App{"Redis", ""}
}

ver := strutil.ReadField(string(output), 2, false, ' ')
ver = strings.TrimLeft(ver, "v=")

return support.App{"Redis", ver}
}

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

switch options.GetS(OPT_COMPLETION) {
case "bash":
fmt.Printf(bash.Generate(info, "rds-payload-generator"))
fmt.Print(bash.Generate(info, "rds-payload-generator"))
case "fish":
fmt.Printf(fish.Generate(info, "rds-payload-generator"))
fmt.Print(fish.Generate(info, "rds-payload-generator"))
case "zsh":
fmt.Printf(zsh.Generate(info, optMap, "rds-payload-generator"))
fmt.Print(zsh.Generate(info, optMap, "rds-payload-generator"))
default:
return 1
}
Expand All @@ -342,6 +365,8 @@ func printMan() {
func genUsage() *usage.Info {
info := usage.NewInfo()

info.AppNameColorTag = colorTagApp

info.AddOption(OPT_DIR, "Path to RDS main dir", "dir")
info.AddOption(OPT_KEYS, "Number of keys {s-}(10-1000000 | default: 5000){!}")
info.AddOption(OPT_RATIO, "Writes/reads ratio {s-}(1-100 | default: 4){!}")
Expand All @@ -367,10 +392,18 @@ func genAbout(gitRev string) *usage.About {
Year: 2006,
Owner: "ESSENTIAL KAOS",
License: "Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>",

AppNameColorTag: colorTagApp,
VersionColorTag: colorTagVer,
DescSeparator: "{s}—{!}",
}

if gitRev != "" {
about.Build = "git:" + gitRev
about.UpdateChecker = usage.UpdateChecker{
"essentialkaos/rds-payload-generator",
update.GitHubChecker,
}
}

return about
Expand Down
Loading

0 comments on commit ce49e7c

Please sign in to comment.