diff --git a/.typos.toml b/.typos.toml index e464888b..f0060d7d 100644 --- a/.typos.toml +++ b/.typos.toml @@ -11,3 +11,4 @@ womens = "womens" mrs_claus = "mrs_claus" NewCFBEncrypter = "NewCFBEncrypter" iterm = "iterm" +O_WRONLY = "O_WRONLY" diff --git a/CHANGELOG.md b/CHANGELOG.md index a31acfaf..96213935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/csv/csv.go b/csv/csv.go index fbe3420a..46966f07 100644 --- a/csv/csv.go +++ b/csv/csv.go @@ -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 diff --git a/ek.go b/ek.go index f1c9656e..305d665a 100644 --- a/ek.go +++ b/ek.go @@ -20,7 +20,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "12.67.1" +const VERSION = "12.68.0" // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/fmtc/examples_test.go b/fmtc/examples_test.go index e1e62a21..3632e927 100644 --- a/fmtc/examples_test.go +++ b/fmtc/examples_test.go @@ -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 @@ -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 diff --git a/go.mod b/go.mod index d399f9f5..1596ab22 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 9f6d9b18..ed93da44 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/options/options.go b/options/options.go index 898dec0a..afe0d6a8 100644 --- a/options/options.go +++ b/options/options.go @@ -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: @@ -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, @@ -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} } diff --git a/options/options_test.go b/options/options_test.go index 425223e3..380152b8 100644 --- a/options/options_test.go +++ b/options/options_test.go @@ -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"}, @@ -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) diff --git a/progress/examples_test.go b/progress/examples_test.go index 5bdd7cca..9dc32828 100644 --- a/progress/examples_test.go +++ b/progress/examples_test.go @@ -18,7 +18,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // -func SimpleExample() { +func ExampleNew_simple() { pb := progress.New(1000, "Counting…") // You can use default settings as a starting point @@ -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() diff --git a/progress/progress.go b/progress/progress.go index d3850321..e882a2a0 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -11,6 +11,7 @@ package progress import ( "fmt" "io" + "math" "strconv" "strings" "sync" @@ -80,6 +81,8 @@ type Settings struct { Width int NameSize int + WindowSizeSec int64 // Window size for passtru reader + IsSize bool } @@ -114,6 +117,7 @@ var DefaultSettings = Settings{ ShowRemaining: true, IsSize: true, Width: 88, + WindowSizeSec: 15.0, } // ////////////////////////////////////////////////////////////////////////////////// // @@ -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() @@ -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) } @@ -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 @@ -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