Skip to content

Commit

Permalink
Merge pull request #306 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.37.0
  • Loading branch information
andyone committed Dec 18, 2021
2 parents 16f511e + 835c21a commit 14e36e4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
## Changelog

### 12.37.0

* `[strutil]` Added helper `Q` for working with default values
* `[usage]` Added color customization for application name and version

### 12.36.0

* `[system]` Added CPU architecture bits info to `SystemInfo`
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Expand Up @@ -19,7 +19,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.36.0"
const VERSION = "12.37.0"

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

Expand Down
10 changes: 10 additions & 0 deletions strutil/example_test.go
Expand Up @@ -13,6 +13,16 @@ import (

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

func ExampleQ() {
var defaultValue = "john"
var user = ""

fmt.Println(Q(user, defaultValue))

// Output:
// john
}

func ExampleConcat() {
fmt.Println(Concat("abc", " ", "123", " ", "ABC"))

Expand Down
11 changes: 11 additions & 0 deletions strutil/strutil.go
Expand Up @@ -24,6 +24,17 @@ var defaultFieldsSeparators = []string{" ", "\t"}

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

// Q is simple helper for working with default values
func Q(v ...string) string {
for _, k := range v {
if k != "" {
return k
}
}

return ""
}

// Concat is method for fast string concatenation
func Concat(s ...string) string {
var buffer bytes.Buffer
Expand Down
6 changes: 6 additions & 0 deletions strutil/strutil_test.go
Expand Up @@ -25,6 +25,12 @@ var _ = Suite(&StrUtilSuite{})

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

func (s *StrUtilSuite) TestQ(c *C) {
c.Assert(Q(), Equals, "")
c.Assert(Q("a"), Equals, "a")
c.Assert(Q("", "", "1"), Equals, "1")
}

func (s *StrUtilSuite) TestConcat(c *C) {
s1 := "abcdef"
s2 := "123456"
Expand Down
3 changes: 3 additions & 0 deletions usage/example_test.go
Expand Up @@ -23,6 +23,9 @@ func ExampleAbout_Render() {
Year: 2009, // Year when company was founded
License: "MIT",
Owner: "John Dow <john@domain.com>",

AppNameColorTag: "{r*}", // Use custom color for application name
VersionColorTag: "{r}", // Use custom color for application version
}

about.Render()
Expand Down
31 changes: 22 additions & 9 deletions usage/usage.go
Expand Up @@ -32,6 +32,15 @@ const _BREADCRUMBS_MIN_SIZE = 8

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

const (
DEFAULT_COMMANDS_COLOR_TAG = "{y}"
DEFAULT_OPTIONS_COLOR_TAG = "{g}"
DEFAULT_APP_NAME_COLOR_TAG = "{c*}"
DEFAULT_APP_VER_COLOR_TAG = "{c}"
)

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

// About contains info about application
type About struct {
App string // App is application name
Expand All @@ -44,14 +53,17 @@ type About struct {
Owner string // Owner is name of owner (company/developer)
BugTracker string // BugTracker is URL of bug tracker

AppNameColorTag string // AppNameColorTag contains default app name color tag
VersionColorTag string // AppNameColorTag contains default app version color tag

// Function for checking application updates
UpdateChecker UpdateChecker
}

// Info contains info about commands, options, and examples
type Info struct {
CommandsColorTag string // CommandsColor contains default commands color
OptionsColorTag string // OptionsColor contains default options color
CommandsColorTag string // CommandsColor contains default commands color tag
OptionsColorTag string // OptionsColor contains default options color tag
Breadcrumbs bool // Use bread crumbs for commands and options output

Name string
Expand Down Expand Up @@ -105,16 +117,14 @@ func NewInfo(args ...string) *Info {
args = args[1:]
}

if name == "" {
name = filepath.Base(os.Args[0])
}
name = strutil.Q(name, filepath.Base(os.Args[0]))

info := &Info{
Name: name,
Args: args,

CommandsColorTag: "{y}",
OptionsColorTag: "{g}",
CommandsColorTag: DEFAULT_COMMANDS_COLOR_TAG,
OptionsColorTag: DEFAULT_OPTIONS_COLOR_TAG,
Breadcrumbs: true,
}

Expand Down Expand Up @@ -273,16 +283,19 @@ func (i *Info) Render() {

// Render prints version info to console
func (a *About) Render() {
nc := strutil.Q(a.AppNameColorTag, DEFAULT_APP_NAME_COLOR_TAG)
vc := strutil.Q(a.VersionColorTag, DEFAULT_APP_VER_COLOR_TAG)

switch {
case a.Build != "":
fmtc.Printf(
"\n{*c}%s {c}%s{!}{s}%s{!} {s-}(%s){!} - %s\n\n",
"\n"+nc+"%s{!} "+vc+"%s{!}{s}%s{!} {s-}(%s){!} - %s\n\n",
a.App, a.Version,
a.Release, a.Build, a.Desc,
)
default:
fmtc.Printf(
"\n{*c}%s {c}%s{!}{s}%s{!} - %s\n\n",
"\n"+nc+"%s{!} "+vc+"%s{!}{s}%s{!} - %s\n\n",
a.App, a.Version,
a.Release, a.Desc,
)
Expand Down

0 comments on commit 14e36e4

Please sign in to comment.