Skip to content

Commit

Permalink
Merge pull request #365 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.68.0
  • Loading branch information
andyone committed Jun 28, 2023
2 parents c0c1d2f + 7909df5 commit a067ad3
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 22 deletions.
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ womens = "womens"
mrs_claus = "mrs_claus"
NewCFBEncrypter = "NewCFBEncrypter"
iterm = "iterm"
O_WRONLY = "O_WRONLY"
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog

### 12.68.0

* `[options]` Improved short options parsing logic
* `[progress]` Added window size configuration for passthru calculator
* Fixed typos

### 12.67.1

* `[options]` Fixed bug with flattening empty arguments
Expand Down
2 changes: 1 addition & 1 deletion csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Reader struct {

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

// ErrEmptyDest is returned by the ReadTo method if empty destintation slice was given
// ErrEmptyDest is returned by the ReadTo method if empty destination slice was given
var ErrEmptyDest = errors.New("Destination slice length must be greater than 1")

// ErrNilReader is returned when reader struct is nil
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.67.1"
const VERSION = "12.68.0"

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

Expand Down
4 changes: 2 additions & 2 deletions fmtc/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func ExamplePrint() {
// Print using named color
Print("{?error}lawngreen text{!}\n")

// Redifine "error" color to 24-bit color
// Redefine "error" color to 24-bit color
NameColor("error", "{#ff0000}")

// Remove named color
Expand Down Expand Up @@ -358,7 +358,7 @@ func ExampleNameColor() {
// Print a message with named color
Print("{?error}lawngreen text{!}\n")

// Redifine "error" color to 24-bit color
// Redefine "error" color to 24-bit color
NameColor("error", "{#ff0000}")

// Print a message with new color
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ go 1.18
require (
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/go-linenoise/v3 v3.4.0
golang.org/x/crypto v0.9.0
golang.org/x/sys v0.8.0
golang.org/x/crypto v0.10.0
golang.org/x/sys v0.9.0
)

require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
)
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3x
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13 changes: 11 additions & 2 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,10 @@ func (opts *Options) parseOptions(rawOpts []string) (Arguments, []error) {
arguments = append(arguments, Argument(curOpt))
continue

case curOptLen > 2 && curOpt[0:2] == "--":
case curOptLen > 2 && curOpt[:2] == "--":
curOptName, curOptValue, err = opts.parseLongOption(curOpt[2:curOptLen])

case curOptLen > 1 && curOpt[0:1] == "-":
case curOptLen > 1 && curOpt[:1] == "-":
curOptName, curOptValue, err = opts.parseShortOption(curOpt[1:curOptLen])

case mixedOpt:
Expand All @@ -519,6 +519,11 @@ func (opts *Options) parseOptions(rawOpts []string) (Arguments, []error) {
continue
}

if curOptName == "" && curOptValue == "" {
arguments = append(arguments, Argument(curOpt))
continue
}

if curOptName != "" && mixedOpt {
errorList = appendError(
errorList,
Expand Down Expand Up @@ -612,6 +617,10 @@ func (opts *Options) parseShortOption(opt string) (string, string, error) {
return opts.short[optName], strings.Join(optSlice[1:], "="), nil
}

if len(opt) > 2 {
return "", "", nil
}

if opts.short[opt] == "" {
return "", "", OptionError{"-" + opt, "", ERROR_UNSUPPORTED}
}
Expand Down
10 changes: 8 additions & 2 deletions options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (s *OptUtilSuite) TestBound(c *C) {
}

func (s *OptUtilSuite) TestGetters(c *C) {
argline := "file.mp3 -s STRING --required TEST -i 320 -b -f 1.098765 -S2 100 -f1 5 -f2 1 -ms ABC --merg-string DEF -mi 6 --merg-int 6 -f3 12 -mf 10.1 -mf 10.1 -i1 5"
argline := "file.mp3 -SAT -s STRING --required TEST -i 320 -b -f 1.098765 -S2 100 -f1 5 -f2 1 -ms ABC --merg-string DEF -mi 6 --merg-int 6 -f3 12 -mf 10.1 -mf 10.1 -i1 5"

optMap := Map{
"s:string": {Type: STRING, Value: "STRING"},
Expand All @@ -220,7 +220,13 @@ func (s *OptUtilSuite) TestGetters(c *C) {
}

opts := NewOptions()
opts.Parse(strings.Split(argline, " "), optMap)
args, errs := opts.Parse(strings.Split(argline, " "), optMap)

c.Assert(errs, HasLen, 0)
c.Assert(args, HasLen, 2)

c.Assert(args.Get(0).String(), Equals, "file.mp3")
c.Assert(args.Get(1).String(), Equals, "-SAT")

c.Assert(opts.GetS("_not_exist_"), Equals, "")
c.Assert(opts.GetI("_not_exist_"), Equals, 0)
Expand Down
4 changes: 2 additions & 2 deletions progress/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

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

func SimpleExample() {
func ExampleNew_simple() {
pb := progress.New(1000, "Counting…")

// You can use default settings as a starting point
Expand All @@ -41,7 +41,7 @@ func SimpleExample() {
pb.Finish() // Stop async progress handling
}

func DownloadExample() {
func ExampleNew_download() {
pb := progress.New(0, "file.zip")
resp, err := req.Request{URL: "https://domain.com/file.zip"}.Get()

Expand Down
16 changes: 12 additions & 4 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package progress
import (
"fmt"
"io"
"math"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -80,6 +81,8 @@ type Settings struct {
Width int
NameSize int

WindowSizeSec int64 // Window size for passtru reader

IsSize bool
}

Expand Down Expand Up @@ -114,6 +117,7 @@ var DefaultSettings = Settings{
ShowRemaining: true,
IsSize: true,
Width: 88,
WindowSizeSec: 15.0,
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -155,7 +159,9 @@ func (b *Bar) Start() {
}

if b.total > 0 {
b.passThruCalc = NewPassThruCalc(b.total, 10.0)
b.passThruCalc = NewPassThruCalc(
b.total, math.Max(1.0, float64(b.settings.WindowSizeSec)),
)
}

go b.renderer()
Expand Down Expand Up @@ -223,7 +229,9 @@ func (b *Bar) SetTotal(v int64) {
b.mu.Lock()

if b.passThruCalc == nil {
b.passThruCalc = NewPassThruCalc(v, 10.0)
b.passThruCalc = NewPassThruCalc(
v, math.Max(1.0, float64(b.settings.WindowSizeSec)),
)
} else {
b.passThruCalc.SetTotal(v)
}
Expand Down Expand Up @@ -277,7 +285,7 @@ func (b *Bar) Add64(v int64) {
atomic.AddInt64(&b.current, v)
}

// IsFinished returns true if progress proccesing is finished
// IsFinished returns true if progress processing is finished
func (b *Bar) IsFinished() bool {
if b == nil {
return false
Expand All @@ -288,7 +296,7 @@ func (b *Bar) IsFinished() bool {
return b.finished
}

// IsStarted returns true if progress proccesing is started
// IsStarted returns true if progress processing is started
func (b *Bar) IsStarted() bool {
if b == nil {
return false
Expand Down

0 comments on commit a067ad3

Please sign in to comment.