Skip to content

Commit

Permalink
Merge pull request #307 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.38.0
  • Loading branch information
andyone committed Dec 31, 2021
2 parents 14e36e4 + 09710b6 commit be0441e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
## Changelog

### 12.38.0

* `[usage]` Improved color customization for application name and version
* `[usage]` Added color customization for application name in usage info

### 12.37.0

* `[strutil]` Added helper `Q` for working with default values
Expand Down
4 changes: 2 additions & 2 deletions ek.go
@@ -1,4 +1,4 @@
// +build !windows
//go:build !windows

// Package ek is a set of auxiliary packages
package ek
Expand All @@ -19,7 +19,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

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

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

Expand Down
58 changes: 29 additions & 29 deletions signal/signal_windows.go
Expand Up @@ -11,35 +11,35 @@ package signal

const (
ABRT = 0
ALRM = 0
BUS = 0
CHLD = 0
CONT = 0
FPE = 0
HUP = 0
ILL = 0
INT = 0
IO = 0
IOT = 0
KILL = 0
PIPE = 0
PROF = 0
QUIT = 0
SEGV = 0
STOP = 0
SYS = 0
TERM = 0
TRAP = 0
TSTP = 0
TTIN = 0
TTOU = 0
URG = 0
USR1 = 0
USR2 = 0
VTALRM = 0
WINCH = 0
XCPU = 0
XFSZ = 0
ALRM = 1
BUS = 2
CHLD = 3
CONT = 4
FPE = 5
HUP = 6
ILL = 7
INT = 8
IO = 9
IOT = 10
KILL = 11
PIPE = 12
PROF = 13
QUIT = 14
SEGV = 15
STOP = 16
SYS = 17
TERM = 18
TRAP = 19
TSTP = 20
TTIN = 21
TTOU = 22
URG = 23
USR1 = 24
USR2 = 25
VTALRM = 26
WINCH = 27
XCPU = 28
XFSZ = 29
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
5 changes: 5 additions & 0 deletions usage/example_test.go
Expand Up @@ -39,6 +39,11 @@ func ExampleNewInfo() {
// You can hardcode the name of the app if you want
info = NewInfo("myapp")

// You can customize some colors
info.AppNameColorTag = "{c}"
info.CommandsColorTag = "{y}"
info.OptionsColorTag = "{m}"

// You can define one or more arguments handled by your program
info = NewInfo("", "files…")
info = NewInfo("", "input", "num-files", "output")
Expand Down
14 changes: 9 additions & 5 deletions usage/usage.go
Expand Up @@ -54,14 +54,15 @@ type About struct {
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
VersionColorTag string // VersionColorTag contains default app version color tag

// Function for checking application updates
UpdateChecker UpdateChecker
}

// Info contains info about commands, options, and examples
type Info struct {
AppNameColorTag string // AppNameColorTag contains default app name color tag
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
Expand All @@ -79,12 +80,13 @@ type Info struct {

// UpdateChecker is a base for all update checkers
type UpdateChecker struct {
Data string
Payload string
CheckFunc func(app, version, data string) (string, time.Time, bool)
}

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

// Command contains info about supported command
type Command struct {
Name string
Desc string
Expand All @@ -93,13 +95,15 @@ type Command struct {
BoundOptions []string
}

// Option contains info about supported option
type Option struct {
Short string
Long string
Desc string
Arg string
}

// Example contains usage example
type Example struct {
Cmd string
Desc string
Expand Down Expand Up @@ -245,7 +249,7 @@ func (i *Info) GetOption(name string) *Option {

// Render prints usage info to console
func (i *Info) Render() {
usageMessage := "\n{*}Usage:{!} " + i.Name
usageMessage := "\n{*}Usage:{!} " + i.AppNameColorTag + i.Name + "{!}"

if len(i.Options) != 0 {
usageMessage += " " + i.OptionsColorTag + "{options}{!}"
Expand Down Expand Up @@ -319,11 +323,11 @@ func (a *About) Render() {
fmtc.Printf("{s-}%s{!}\n", a.License)
}

if a.UpdateChecker.CheckFunc != nil && a.UpdateChecker.Data != "" {
if a.UpdateChecker.CheckFunc != nil && a.UpdateChecker.Payload != "" {
newVersion, releaseDate, hasUpdate := a.UpdateChecker.CheckFunc(
a.App,
a.Version,
a.UpdateChecker.Data,
a.UpdateChecker.Payload,
)

if hasUpdate && isNewerVersion(a.Version, newVersion) {
Expand Down

0 comments on commit be0441e

Please sign in to comment.