diff --git a/backend/_example/memory_store/go.mod b/backend/_example/memory_store/go.mod index 1dc418ad..40910062 100644 --- a/backend/_example/memory_store/go.mod +++ b/backend/_example/memory_store/go.mod @@ -5,7 +5,6 @@ go 1.14 require ( github.com/go-pkgz/jrpc v0.1.0 github.com/go-pkgz/lgr v0.7.0 - github.com/jessevdk/go-flags v0.0.0-20180331124232-1c38ed7ad0cc github.com/pkg/errors v0.9.1 github.com/rs/xid v1.2.1 github.com/stretchr/testify v1.5.1 diff --git a/backend/_example/memory_store/go.sum b/backend/_example/memory_store/go.sum index cd7998e2..617ccdf2 100644 --- a/backend/_example/memory_store/go.sum +++ b/backend/_example/memory_store/go.sum @@ -157,6 +157,8 @@ github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/rtree v0.0.0-20180113144539-6cd427091e0e/go.mod h1:/h+UnNGt0IhNNJLkGikcdcJqm66zGD/uJGMRxK/9+Ao= github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563/go.mod h1:mLqSmt7Dv/CNneF2wfcChfN1rvapyQr01LGKnKex0DQ= +github.com/umputun/go-flags v0.0.0-20180331124232-1c38ed7ad0cc/go.mod h1:nvqHT2I0/X1L/Y0MrjF9GSLb6JCOnJwGfaDjgzSfAvs= +github.com/umputun/go-flags v1.5.1/go.mod h1:nTbvsO/hKqe7Utri/NoyN18GR3+EWf+9RrmsdwdhrEc= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.0.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= diff --git a/backend/_example/memory_store/main.go b/backend/_example/memory_store/main.go index b7751c91..67def3e0 100644 --- a/backend/_example/memory_store/main.go +++ b/backend/_example/memory_store/main.go @@ -12,7 +12,7 @@ import ( "github.com/go-pkgz/jrpc" log "github.com/go-pkgz/lgr" - "github.com/jessevdk/go-flags" + "github.com/umputun/go-flags" "github.com/umputun/remark/memory_store/accessor" "github.com/umputun/remark/memory_store/server" diff --git a/backend/app/cmd/avatar_test.go b/backend/app/cmd/avatar_test.go index e31a53b8..43b3b476 100644 --- a/backend/app/cmd/avatar_test.go +++ b/backend/app/cmd/avatar_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/go-pkgz/auth/avatar" - flags "github.com/jessevdk/go-flags" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/umputun/go-flags" ) func TestAvatar_Execute(t *testing.T) { diff --git a/backend/app/cmd/backup_test.go b/backend/app/cmd/backup_test.go index 60a8bf7e..babe7438 100644 --- a/backend/app/cmd/backup_test.go +++ b/backend/app/cmd/backup_test.go @@ -8,7 +8,8 @@ import ( "os" "testing" - flags "github.com/jessevdk/go-flags" + "github.com/umputun/go-flags" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/backend/app/cmd/cleanup_test.go b/backend/app/cmd/cleanup_test.go index 02ef3b70..829cef78 100644 --- a/backend/app/cmd/cleanup_test.go +++ b/backend/app/cmd/cleanup_test.go @@ -10,9 +10,9 @@ import ( "time" "github.com/go-chi/chi" - flags "github.com/jessevdk/go-flags" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/umputun/go-flags" "github.com/umputun/remark/backend/app/store" ) diff --git a/backend/app/cmd/import_test.go b/backend/app/cmd/import_test.go index 94080520..127491a2 100644 --- a/backend/app/cmd/import_test.go +++ b/backend/app/cmd/import_test.go @@ -9,7 +9,8 @@ import ( "time" log "github.com/go-pkgz/lgr" - flags "github.com/jessevdk/go-flags" + "github.com/umputun/go-flags" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/backend/app/cmd/remap_test.go b/backend/app/cmd/remap_test.go index d215ffb4..d2625218 100644 --- a/backend/app/cmd/remap_test.go +++ b/backend/app/cmd/remap_test.go @@ -6,7 +6,8 @@ import ( "net/http/httptest" "testing" - "github.com/jessevdk/go-flags" + "github.com/umputun/go-flags" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/backend/app/cmd/restore_test.go b/backend/app/cmd/restore_test.go index 4ff59129..c7abf7aa 100644 --- a/backend/app/cmd/restore_test.go +++ b/backend/app/cmd/restore_test.go @@ -7,7 +7,8 @@ import ( "net/http/httptest" "testing" - flags "github.com/jessevdk/go-flags" + "github.com/umputun/go-flags" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/backend/app/cmd/server_test.go b/backend/app/cmd/server_test.go index 52577722..64e8a0cd 100644 --- a/backend/app/cmd/server_test.go +++ b/backend/app/cmd/server_test.go @@ -17,7 +17,7 @@ import ( "github.com/dgrijalva/jwt-go" "github.com/go-pkgz/auth/token" - "github.com/jessevdk/go-flags" + "github.com/umputun/go-flags" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/backend/app/main.go b/backend/app/main.go index 4fd6b51a..9ca2331a 100644 --- a/backend/app/main.go +++ b/backend/app/main.go @@ -8,7 +8,7 @@ import ( "syscall" log "github.com/go-pkgz/lgr" - "github.com/jessevdk/go-flags" + "github.com/umputun/go-flags" "github.com/umputun/remark/backend/app/cmd" ) diff --git a/backend/go.mod b/backend/go.mod index f32d4673..051b2a6e 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -22,7 +22,6 @@ require ( github.com/google/uuid v1.1.1 github.com/gorilla/feeds v1.1.1 github.com/hashicorp/go-multierror v1.1.0 - github.com/jessevdk/go-flags v0.0.0-20180331124232-1c38ed7ad0cc github.com/kyokomi/emoji v2.2.1+incompatible github.com/microcosm-cc/bluemonday v1.0.2 github.com/patrickmn/go-cache v2.1.0+incompatible @@ -31,6 +30,7 @@ require ( github.com/rs/xid v1.2.1 github.com/russross/blackfriday/v2 v2.0.1 github.com/stretchr/testify v1.5.1 + github.com/umputun/go-flags v1.5.1 go.etcd.io/bbolt v1.3.4 golang.org/x/crypto v0.0.0-20200406173513-056763e48d71 golang.org/x/image v0.0.0-20200119044424-58c23975cae1 diff --git a/backend/go.sum b/backend/go.sum index a997a309..60f55299 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -130,10 +130,6 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N1Vk= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= -github.com/jessevdk/go-flags v0.0.0-20180331124232-1c38ed7ad0cc h1:0L2sGkaj6MWuV1BfXsrLJ/+XA8RzKKVsYlLVXNkK1Lw= -github.com/jessevdk/go-flags v0.0.0-20180331124232-1c38ed7ad0cc/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -214,6 +210,8 @@ github.com/tidwall/rtree v0.0.0-20180113144539-6cd427091e0e h1:+NL1GDIUOKxVfbp2K github.com/tidwall/rtree v0.0.0-20180113144539-6cd427091e0e/go.mod h1:/h+UnNGt0IhNNJLkGikcdcJqm66zGD/uJGMRxK/9+Ao= github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563 h1:Otn9S136ELckZ3KKDyCkxapfufrqDqwmGjcHfAyXRrE= github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563/go.mod h1:mLqSmt7Dv/CNneF2wfcChfN1rvapyQr01LGKnKex0DQ= +github.com/umputun/go-flags v1.5.1 h1:vRauoXV3Ultt1HrxivSxowbintgZLJE+EcBy5ta3/mY= +github.com/umputun/go-flags v1.5.1/go.mod h1:nTbvsO/hKqe7Utri/NoyN18GR3+EWf+9RrmsdwdhrEc= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.0.0 h1:BwIoZQbBsTo3v2F5lz5Oy3TlTq4wLKTLV260EVTEWco= diff --git a/backend/vendor/github.com/jessevdk/go-flags/.travis.yml b/backend/vendor/github.com/umputun/go-flags/.travis.yml similarity index 94% rename from backend/vendor/github.com/jessevdk/go-flags/.travis.yml rename to backend/vendor/github.com/umputun/go-flags/.travis.yml index 0f0728d2..06dbe728 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/.travis.yml +++ b/backend/vendor/github.com/umputun/go-flags/.travis.yml @@ -6,8 +6,6 @@ os: go: - 1.x - - 1.7.x - - 1.8.x - 1.9.x - 1.10.x @@ -17,7 +15,7 @@ install: - go build -v ./... # linting - - go get github.com/golang/lint/golint + - go get -v golang.org/x/lint/golint # code coverage - go get golang.org/x/tools/cmd/cover diff --git a/backend/vendor/github.com/jessevdk/go-flags/LICENSE b/backend/vendor/github.com/umputun/go-flags/LICENSE similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/LICENSE rename to backend/vendor/github.com/umputun/go-flags/LICENSE diff --git a/backend/vendor/github.com/jessevdk/go-flags/README.md b/backend/vendor/github.com/umputun/go-flags/README.md similarity index 95% rename from backend/vendor/github.com/jessevdk/go-flags/README.md rename to backend/vendor/github.com/umputun/go-flags/README.md index 3b02394e..f22650b2 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/README.md +++ b/backend/vendor/github.com/umputun/go-flags/README.md @@ -61,6 +61,9 @@ var opts struct { // Example of a required flag Name string `short:"n" long:"name" description:"A name" required:"true"` + // Example of a flag restricted to a pre-defined set of strings + Animal string `long:"animal" choice:"cat" choice:"dog"` + // Example of a value name File string `short:"f" long:"file" description:"A file" value-name:"FILE"` @@ -91,6 +94,7 @@ args := []string{ "-vv", "--offset=5", "-n", "Me", + "--animal", "dog", // anything other than "cat" or "dog" will raise an error "-p", "3", "-s", "hello", "-s", "world", @@ -115,6 +119,7 @@ if err != nil { fmt.Printf("Verbosity: %v\n", opts.Verbose) fmt.Printf("Offset: %d\n", opts.Offset) fmt.Printf("Name: %s\n", opts.Name) +fmt.Printf("Animal: %s\n", opts.Animal) fmt.Printf("Ptr: %d\n", *opts.Ptr) fmt.Printf("StringSlice: %v\n", opts.StringSlice) fmt.Printf("PtrSlice: [%v %v]\n", *opts.PtrSlice[0], *opts.PtrSlice[1]) diff --git a/backend/vendor/github.com/jessevdk/go-flags/arg.go b/backend/vendor/github.com/umputun/go-flags/arg.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/arg.go rename to backend/vendor/github.com/umputun/go-flags/arg.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/check_crosscompile.sh b/backend/vendor/github.com/umputun/go-flags/check_crosscompile.sh similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/check_crosscompile.sh rename to backend/vendor/github.com/umputun/go-flags/check_crosscompile.sh diff --git a/backend/vendor/github.com/jessevdk/go-flags/closest.go b/backend/vendor/github.com/umputun/go-flags/closest.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/closest.go rename to backend/vendor/github.com/umputun/go-flags/closest.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/command.go b/backend/vendor/github.com/umputun/go-flags/command.go similarity index 99% rename from backend/vendor/github.com/jessevdk/go-flags/command.go rename to backend/vendor/github.com/umputun/go-flags/command.go index 486bacba..879465d7 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/command.go +++ b/backend/vendor/github.com/umputun/go-flags/command.go @@ -438,7 +438,7 @@ func (c *Command) match(name string) bool { return false } -func (c *Command) hasCliOptions() bool { +func (c *Command) hasHelpOptions() bool { ret := false c.eachGroup(func(g *Group) { @@ -447,7 +447,7 @@ func (c *Command) hasCliOptions() bool { } for _, opt := range g.options { - if opt.canCli() { + if opt.showInHelp() { ret = true } } diff --git a/backend/vendor/github.com/jessevdk/go-flags/completion.go b/backend/vendor/github.com/umputun/go-flags/completion.go similarity index 98% rename from backend/vendor/github.com/jessevdk/go-flags/completion.go rename to backend/vendor/github.com/umputun/go-flags/completion.go index 7a7a08b9..813a672c 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/completion.go +++ b/backend/vendor/github.com/umputun/go-flags/completion.go @@ -2,6 +2,7 @@ package flags import ( "fmt" + "os" "path/filepath" "reflect" "sort" @@ -62,6 +63,11 @@ func completionsWithoutDescriptions(items []string) []Completion { // prefix. func (f *Filename) Complete(match string) []Completion { ret, _ := filepath.Glob(match + "*") + if len(ret) == 1 { + if info, err := os.Stat(ret[0]); err == nil && info.IsDir() { + ret[0] = ret[0] + "/" + } + } return completionsWithoutDescriptions(ret) } diff --git a/backend/vendor/github.com/jessevdk/go-flags/convert.go b/backend/vendor/github.com/umputun/go-flags/convert.go similarity index 95% rename from backend/vendor/github.com/jessevdk/go-flags/convert.go rename to backend/vendor/github.com/umputun/go-flags/convert.go index 984aac89..cda29b2f 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/convert.go +++ b/backend/vendor/github.com/umputun/go-flags/convert.go @@ -28,6 +28,15 @@ type Unmarshaler interface { UnmarshalFlag(value string) error } +// ValueValidator is the interface implemented by types that can validate a +// flag argument themselves. The provided value is directly passed from the +// command line. +type ValueValidator interface { + // IsValidValue returns an error if the provided string value is valid for + // the flag. + IsValidValue(value string) error +} + func getBase(options multiTag, base int) (int, error) { sbase := options.Get("base") diff --git a/backend/vendor/github.com/jessevdk/go-flags/error.go b/backend/vendor/github.com/umputun/go-flags/error.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/error.go rename to backend/vendor/github.com/umputun/go-flags/error.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/flags.go b/backend/vendor/github.com/umputun/go-flags/flags.go similarity index 98% rename from backend/vendor/github.com/jessevdk/go-flags/flags.go rename to backend/vendor/github.com/umputun/go-flags/flags.go index e627c99f..ac2157dd 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/flags.go +++ b/backend/vendor/github.com/umputun/go-flags/flags.go @@ -109,7 +109,8 @@ The following is a list of tags for struct fields supported by go-flags: value-name: the name of the argument value (to be shown in the help) (optional) choice: limits the values for an option to a set of values. - This tag can be specified multiple times (optional) + Repeat this tag once for each allowable value. + e.g. `long:"animal" choice:"cat" choice:"dog"` hidden: if non-empty, the option is not visible in the help or man page. base: a base (radix) used to convert strings to integer values, the diff --git a/backend/vendor/github.com/umputun/go-flags/go.mod b/backend/vendor/github.com/umputun/go-flags/go.mod new file mode 100644 index 00000000..31425fa0 --- /dev/null +++ b/backend/vendor/github.com/umputun/go-flags/go.mod @@ -0,0 +1,3 @@ +module github.com/umputun/go-flags + +go 1.12 diff --git a/backend/vendor/github.com/jessevdk/go-flags/group.go b/backend/vendor/github.com/umputun/go-flags/group.go similarity index 98% rename from backend/vendor/github.com/jessevdk/go-flags/group.go rename to backend/vendor/github.com/umputun/go-flags/group.go index 9341d23f..ec909e51 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/group.go +++ b/backend/vendor/github.com/umputun/go-flags/group.go @@ -168,6 +168,18 @@ func (g *Group) optionByName(name string, namematch func(*Option, string) bool) return retopt } +func (g *Group) showInHelp() bool { + if g.Hidden { + return false + } + for _, opt := range g.options { + if opt.showInHelp() { + return true + } + } + return false +} + func (g *Group) eachGroup(f func(*Group)) { f(g) diff --git a/backend/vendor/github.com/jessevdk/go-flags/help.go b/backend/vendor/github.com/umputun/go-flags/help.go similarity index 94% rename from backend/vendor/github.com/jessevdk/go-flags/help.go rename to backend/vendor/github.com/umputun/go-flags/help.go index 8e3eba98..068fce15 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/help.go +++ b/backend/vendor/github.com/umputun/go-flags/help.go @@ -72,6 +72,9 @@ func (p *Parser) getAlignmentInfo() alignmentInfo { var prevcmd *Command p.eachActiveGroup(func(c *Command, grp *Group) { + if !grp.showInHelp() { + return + } if c != prevcmd { for _, arg := range c.args { ret.updateLen(arg.Name, c != p.Command) @@ -79,7 +82,7 @@ func (p *Parser) getAlignmentInfo() alignmentInfo { } for _, info := range grp.options { - if !info.canCli() { + if !info.showInHelp() { continue } @@ -305,7 +308,7 @@ func (p *Parser) WriteHelp(writer io.Writer) { } } else if us, ok := allcmd.data.(Usage); ok { usage = us.Usage() - } else if allcmd.hasCliOptions() { + } else if allcmd.hasHelpOptions() { usage = fmt.Sprintf("[%s-OPTIONS]", allcmd.Name) } @@ -393,7 +396,7 @@ func (p *Parser) WriteHelp(writer io.Writer) { } for _, info := range grp.options { - if !info.canCli() || info.Hidden { + if !info.showInHelp() { continue } @@ -489,3 +492,23 @@ func (p *Parser) WriteHelp(writer io.Writer) { wr.Flush() } + +// WroteHelp is a helper to test the error from ParseArgs() to +// determine if the help message was written. It is safe to +// call without first checking that error is nil. +func WroteHelp(err error) bool { + if err == nil { // No error + return false + } + + flagError, ok := err.(*Error) + if !ok { // Not a go-flag error + return false + } + + if flagError.Type != ErrHelp { // Did not print the help message + return false + } + + return true +} diff --git a/backend/vendor/github.com/jessevdk/go-flags/ini.go b/backend/vendor/github.com/umputun/go-flags/ini.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/ini.go rename to backend/vendor/github.com/umputun/go-flags/ini.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/man.go b/backend/vendor/github.com/umputun/go-flags/man.go similarity index 92% rename from backend/vendor/github.com/jessevdk/go-flags/man.go rename to backend/vendor/github.com/umputun/go-flags/man.go index c2cebae6..97372b76 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/man.go +++ b/backend/vendor/github.com/umputun/go-flags/man.go @@ -3,7 +3,9 @@ package flags import ( "fmt" "io" + "os" "runtime" + "strconv" "strings" "time" ) @@ -38,7 +40,7 @@ func formatForMan(wr io.Writer, s string) { func writeManPageOptions(wr io.Writer, grp *Group) { grp.eachGroup(func(group *Group) { - if group.Hidden || len(group.options) == 0 { + if !group.showInHelp() { return } @@ -54,7 +56,7 @@ func writeManPageOptions(wr io.Writer, grp *Group) { } for _, opt := range group.options { - if !opt.canCli() || opt.Hidden { + if !opt.showInHelp() { continue } @@ -148,12 +150,12 @@ func writeManPageCommand(wr io.Writer, name string, root *Command, command *Comm var usage string if us, ok := command.data.(Usage); ok { usage = us.Usage() - } else if command.hasCliOptions() { + } else if command.hasHelpOptions() { usage = fmt.Sprintf("[%s-OPTIONS]", command.Name) } var pre string - if root.hasCliOptions() { + if root.hasHelpOptions() { pre = fmt.Sprintf("%s [OPTIONS] %s", root.Name, command.Name) } else { pre = fmt.Sprintf("%s %s", root.Name, command.Name) @@ -175,6 +177,14 @@ func writeManPageCommand(wr io.Writer, name string, root *Command, command *Comm // writer. func (p *Parser) WriteManPage(wr io.Writer) { t := time.Now() + source_date_epoch := os.Getenv("SOURCE_DATE_EPOCH") + if source_date_epoch != "" { + sde, err := strconv.ParseInt(source_date_epoch, 10, 64) + if err != nil { + panic(fmt.Sprintf("Invalid SOURCE_DATE_EPOCH: %s", err)) + } + t = time.Unix(sde, 0) + } fmt.Fprintf(wr, ".TH %s 1 \"%s\"\n", manQuote(p.Name), t.Format("2 January 2006")) fmt.Fprintln(wr, ".SH NAME") diff --git a/backend/vendor/github.com/jessevdk/go-flags/multitag.go b/backend/vendor/github.com/umputun/go-flags/multitag.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/multitag.go rename to backend/vendor/github.com/umputun/go-flags/multitag.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/option.go b/backend/vendor/github.com/umputun/go-flags/option.go similarity index 93% rename from backend/vendor/github.com/jessevdk/go-flags/option.go rename to backend/vendor/github.com/umputun/go-flags/option.go index c681c39d..5cebb54c 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/option.go +++ b/backend/vendor/github.com/umputun/go-flags/option.go @@ -280,8 +280,8 @@ func (option *Option) set(value *string) error { return convert("", option.value, option.tag) } -func (option *Option) canCli() bool { - return option.ShortName != 0 || len(option.LongName) != 0 +func (option *Option) showInHelp() bool { + return !option.Hidden && (option.ShortName != 0 || len(option.LongName) != 0) } func (option *Option) canArgument() bool { @@ -389,6 +389,30 @@ func (option *Option) isUnmarshaler() Unmarshaler { return nil } +func (option *Option) isValueValidator() ValueValidator { + v := option.value + + for { + if !v.CanInterface() { + break + } + + i := v.Interface() + + if u, ok := i.(ValueValidator); ok { + return u + } + + if !v.CanAddr() { + break + } + + v = v.Addr() + } + + return nil +} + func (option *Option) isBool() bool { tp := option.value.Type() @@ -507,3 +531,13 @@ func (option *Option) shortAndLongName() string { return ret.String() } + +func (option *Option) isValidValue(arg string) error { + if validator := option.isValueValidator(); validator != nil { + return validator.IsValidValue(arg) + } + if argumentIsOption(arg) && !(option.isSignedNumber() && len(arg) > 1 && arg[0] == '-' && arg[1] >= '0' && arg[1] <= '9') { + return fmt.Errorf("expected argument for flag `%s', but got option `%s'", option, arg) + } + return nil +} diff --git a/backend/vendor/github.com/jessevdk/go-flags/optstyle_other.go b/backend/vendor/github.com/umputun/go-flags/optstyle_other.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/optstyle_other.go rename to backend/vendor/github.com/umputun/go-flags/optstyle_other.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/optstyle_windows.go b/backend/vendor/github.com/umputun/go-flags/optstyle_windows.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/optstyle_windows.go rename to backend/vendor/github.com/umputun/go-flags/optstyle_windows.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/parser.go b/backend/vendor/github.com/umputun/go-flags/parser.go similarity index 96% rename from backend/vendor/github.com/jessevdk/go-flags/parser.go rename to backend/vendor/github.com/umputun/go-flags/parser.go index 042930c4..a5347b0a 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/parser.go +++ b/backend/vendor/github.com/umputun/go-flags/parser.go @@ -241,6 +241,7 @@ func (p *Parser) ParseArgs(args []string) ([]string, error) { p.fillParseState(s) for !s.eof() { + var err error arg := s.pop() // When PassDoubleDash is set and we encounter a --, then @@ -251,6 +252,20 @@ func (p *Parser) ParseArgs(args []string) ([]string, error) { } if !argumentIsOption(arg) { + if (p.Options&PassAfterNonOption) != None && s.lookup.commands[arg] == nil { + // If PassAfterNonOption is set then all remaining arguments + // are considered positional + if err = s.addArgs(s.arg); err != nil { + break + } + + if err = s.addArgs(s.args...); err != nil { + break + } + + break + } + // Note: this also sets s.err, so we can just check for // nil here and use s.err later if p.parseNonOption(s) != nil { @@ -260,8 +275,6 @@ func (p *Parser) ParseArgs(args []string) ([]string, error) { continue } - var err error - prefix, optname, islong := stripOptionPrefix(arg) optname, _, argument := splitOption(prefix, optname, islong) @@ -519,8 +532,8 @@ func (p *Parser) parseOption(s *parseState, name string, option *Option, canarg } else { arg = s.pop() - if argumentIsOption(arg) && !(option.isSignedNumber() && len(arg) > 1 && arg[0] == '-' && arg[1] >= '0' && arg[1] <= '9') { - return newErrorf(ErrExpectedArgument, "expected argument for flag `%s', but got option `%s'", option, arg) + if validationErr := option.isValidValue(arg); validationErr != nil { + return newErrorf(ErrExpectedArgument, validationErr.Error()) } else if p.Options&PassDoubleDash != 0 && arg == "--" { return newErrorf(ErrExpectedArgument, "expected argument for flag `%s', but got double dash `--'", option) } @@ -653,23 +666,7 @@ func (p *Parser) parseNonOption(s *parseState) error { } } - if (p.Options & PassAfterNonOption) != None { - // If PassAfterNonOption is set then all remaining arguments - // are considered positional - if err := s.addArgs(s.arg); err != nil { - return err - } - - if err := s.addArgs(s.args...); err != nil { - return err - } - - s.args = []string{} - } else { - return s.addArgs(s.arg) - } - - return nil + return s.addArgs(s.arg) } func (p *Parser) showBuiltinHelp() error { diff --git a/backend/vendor/github.com/jessevdk/go-flags/termsize.go b/backend/vendor/github.com/umputun/go-flags/termsize.go similarity index 86% rename from backend/vendor/github.com/jessevdk/go-flags/termsize.go rename to backend/vendor/github.com/umputun/go-flags/termsize.go index 1ca6a850..29b1110b 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/termsize.go +++ b/backend/vendor/github.com/umputun/go-flags/termsize.go @@ -1,4 +1,4 @@ -// +build !windows,!plan9,!solaris,!appengine +// +build !windows,!plan9,!solaris,!appengine,!wasm package flags diff --git a/backend/vendor/github.com/jessevdk/go-flags/termsize_nosysioctl.go b/backend/vendor/github.com/umputun/go-flags/termsize_nosysioctl.go similarity index 59% rename from backend/vendor/github.com/jessevdk/go-flags/termsize_nosysioctl.go rename to backend/vendor/github.com/umputun/go-flags/termsize_nosysioctl.go index 3d5385b0..12a54580 100644 --- a/backend/vendor/github.com/jessevdk/go-flags/termsize_nosysioctl.go +++ b/backend/vendor/github.com/umputun/go-flags/termsize_nosysioctl.go @@ -1,4 +1,4 @@ -// +build windows plan9 solaris appengine +// +build plan9 solaris appengine wasm package flags diff --git a/backend/vendor/github.com/umputun/go-flags/termsize_windows.go b/backend/vendor/github.com/umputun/go-flags/termsize_windows.go new file mode 100644 index 00000000..5c0fa6ba --- /dev/null +++ b/backend/vendor/github.com/umputun/go-flags/termsize_windows.go @@ -0,0 +1,85 @@ +// +build windows + +package flags + +import ( + "syscall" + "unsafe" +) + +type ( + SHORT int16 + WORD uint16 + + SMALL_RECT struct { + Left SHORT + Top SHORT + Right SHORT + Bottom SHORT + } + + COORD struct { + X SHORT + Y SHORT + } + + CONSOLE_SCREEN_BUFFER_INFO struct { + Size COORD + CursorPosition COORD + Attributes WORD + Window SMALL_RECT + MaximumWindowSize COORD + } +) + +var kernel32DLL = syscall.NewLazyDLL("kernel32.dll") +var getConsoleScreenBufferInfoProc = kernel32DLL.NewProc("GetConsoleScreenBufferInfo") + +func getError(r1, r2 uintptr, lastErr error) error { + // If the function fails, the return value is zero. + if r1 == 0 { + if lastErr != nil { + return lastErr + } + return syscall.EINVAL + } + return nil +} + +func getStdHandle(stdhandle int) (uintptr, error) { + handle, err := syscall.GetStdHandle(stdhandle) + if err != nil { + return 0, err + } + return uintptr(handle), nil +} + +// GetConsoleScreenBufferInfo retrieves information about the specified console screen buffer. +// http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx +func GetConsoleScreenBufferInfo(handle uintptr) (*CONSOLE_SCREEN_BUFFER_INFO, error) { + var info CONSOLE_SCREEN_BUFFER_INFO + if err := getError(getConsoleScreenBufferInfoProc.Call(handle, uintptr(unsafe.Pointer(&info)), 0)); err != nil { + return nil, err + } + return &info, nil +} + +func getTerminalColumns() int { + defaultWidth := 80 + + stdoutHandle, err := getStdHandle(syscall.STD_OUTPUT_HANDLE) + if err != nil { + return defaultWidth + } + + info, err := GetConsoleScreenBufferInfo(stdoutHandle) + if err != nil { + return defaultWidth + } + + if info.MaximumWindowSize.X > 0 { + return int(info.MaximumWindowSize.X) + } + + return defaultWidth +} diff --git a/backend/vendor/github.com/jessevdk/go-flags/tiocgwinsz_bsdish.go b/backend/vendor/github.com/umputun/go-flags/tiocgwinsz_bsdish.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/tiocgwinsz_bsdish.go rename to backend/vendor/github.com/umputun/go-flags/tiocgwinsz_bsdish.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/tiocgwinsz_linux.go b/backend/vendor/github.com/umputun/go-flags/tiocgwinsz_linux.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/tiocgwinsz_linux.go rename to backend/vendor/github.com/umputun/go-flags/tiocgwinsz_linux.go diff --git a/backend/vendor/github.com/jessevdk/go-flags/tiocgwinsz_other.go b/backend/vendor/github.com/umputun/go-flags/tiocgwinsz_other.go similarity index 100% rename from backend/vendor/github.com/jessevdk/go-flags/tiocgwinsz_other.go rename to backend/vendor/github.com/umputun/go-flags/tiocgwinsz_other.go diff --git a/backend/vendor/modules.txt b/backend/vendor/modules.txt index 58be952d..30cb119d 100644 --- a/backend/vendor/modules.txt +++ b/backend/vendor/modules.txt @@ -1,13 +1,10 @@ # cloud.google.com/go v0.40.0 cloud.google.com/go/compute/metadata # github.com/Depado/bfchroma v1.2.0 -## explicit github.com/Depado/bfchroma # github.com/PuerkitoBio/goquery v1.5.1 -## explicit github.com/PuerkitoBio/goquery # github.com/alecthomas/chroma v0.7.2 -## explicit github.com/alecthomas/chroma github.com/alecthomas/chroma/formatters/html github.com/alecthomas/chroma/lexers @@ -48,32 +45,25 @@ github.com/davecgh/go-spew/spew github.com/dghubble/oauth1 github.com/dghubble/oauth1/twitter # github.com/dgrijalva/jwt-go v3.2.0+incompatible -## explicit github.com/dgrijalva/jwt-go # github.com/didip/tollbooth v4.0.2+incompatible -## explicit github.com/didip/tollbooth github.com/didip/tollbooth/errors github.com/didip/tollbooth/libstring github.com/didip/tollbooth/limiter # github.com/didip/tollbooth_chi v0.0.0-20170928041846-6ab5f3083f3d -## explicit github.com/didip/tollbooth_chi # github.com/dlclark/regexp2 v1.1.6 github.com/dlclark/regexp2 github.com/dlclark/regexp2/syntax # github.com/go-chi/chi v4.1.0+incompatible -## explicit github.com/go-chi/chi github.com/go-chi/chi/middleware # github.com/go-chi/cors v1.1.1 -## explicit github.com/go-chi/cors # github.com/go-chi/render v1.0.1 -## explicit github.com/go-chi/render # github.com/go-pkgz/auth v0.10.1 -## explicit github.com/go-pkgz/auth github.com/go-pkgz/auth/avatar github.com/go-pkgz/auth/logger @@ -82,24 +72,18 @@ github.com/go-pkgz/auth/provider github.com/go-pkgz/auth/provider/sender github.com/go-pkgz/auth/token # github.com/go-pkgz/jrpc v0.1.0 -## explicit github.com/go-pkgz/jrpc # github.com/go-pkgz/lcw v0.5.0 -## explicit github.com/go-pkgz/lcw # github.com/go-pkgz/lgr v0.7.0 -## explicit github.com/go-pkgz/lgr # github.com/go-pkgz/repeater v1.1.3 -## explicit github.com/go-pkgz/repeater github.com/go-pkgz/repeater/strategy # github.com/go-pkgz/rest v1.5.0 -## explicit github.com/go-pkgz/rest github.com/go-pkgz/rest/logger # github.com/go-pkgz/syncs v1.1.1 -## explicit github.com/go-pkgz/syncs # github.com/go-redis/redis/v7 v7.0.0-beta.4 github.com/go-redis/redis/v7 @@ -116,62 +100,49 @@ github.com/golang/protobuf/proto # github.com/golang/snappy v0.0.1 github.com/golang/snappy # github.com/google/uuid v1.1.1 -## explicit github.com/google/uuid # github.com/gorilla/feeds v1.1.1 -## explicit github.com/gorilla/feeds # github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/errwrap # github.com/hashicorp/go-multierror v1.1.0 -## explicit github.com/hashicorp/go-multierror # github.com/hashicorp/golang-lru v0.5.3 github.com/hashicorp/golang-lru github.com/hashicorp/golang-lru/simplelru -# github.com/jessevdk/go-flags v0.0.0-20180331124232-1c38ed7ad0cc -## explicit -github.com/jessevdk/go-flags # github.com/kyokomi/emoji v2.2.1+incompatible -## explicit github.com/kyokomi/emoji # github.com/microcosm-cc/bluemonday v1.0.2 -## explicit github.com/microcosm-cc/bluemonday # github.com/nullrocks/identicon v0.0.0-20180626043057-7875f45b0022 github.com/nullrocks/identicon # github.com/patrickmn/go-cache v2.1.0+incompatible -## explicit github.com/patrickmn/go-cache # github.com/pkg/errors v0.9.1 -## explicit github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib/difflib # github.com/rakyll/statik v0.1.7 -## explicit github.com/rakyll/statik/fs # github.com/rs/xid v1.2.1 -## explicit github.com/rs/xid # github.com/russross/blackfriday/v2 v2.0.1 -## explicit github.com/russross/blackfriday/v2 # github.com/shurcooL/sanitized_anchor_name v1.0.0 github.com/shurcooL/sanitized_anchor_name # github.com/stretchr/objx v0.1.0 github.com/stretchr/objx # github.com/stretchr/testify v1.5.1 -## explicit github.com/stretchr/testify/assert github.com/stretchr/testify/mock github.com/stretchr/testify/require +# github.com/umputun/go-flags v1.5.1 +github.com/umputun/go-flags # github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c github.com/xdg/scram # github.com/xdg/stringprep v1.0.0 github.com/xdg/stringprep # go.etcd.io/bbolt v1.3.4 -## explicit go.etcd.io/bbolt # go.mongodb.org/mongo-driver v1.1.1 go.mongodb.org/mongo-driver/bson @@ -204,16 +175,13 @@ go.mongodb.org/mongo-driver/x/mongo/driver/topology go.mongodb.org/mongo-driver/x/mongo/driver/uuid go.mongodb.org/mongo-driver/x/mongo/driver/wiremessage # golang.org/x/crypto v0.0.0-20200406173513-056763e48d71 -## explicit golang.org/x/crypto/acme golang.org/x/crypto/acme/autocert golang.org/x/crypto/pbkdf2 # golang.org/x/image v0.0.0-20200119044424-58c23975cae1 -## explicit golang.org/x/image/draw golang.org/x/image/math/f64 # golang.org/x/net v0.0.0-20200202094626-16171245cfb2 -## explicit golang.org/x/net/context golang.org/x/net/context/ctxhttp golang.org/x/net/html