diff options
| -rw-r--r-- | cmd/license/main.go | 10 | ||||
| -rw-r--r-- | docs/man1/ghstat.1 | 75 | ||||
| -rw-r--r-- | go.mod | 3 | ||||
| -rw-r--r-- | go.sum | 15 | ||||
| -rw-r--r-- | internal/internal.go | 22 |
5 files changed, 49 insertions, 76 deletions
diff --git a/cmd/license/main.go b/cmd/license/main.go index d45b30f..738cf2e 100644 --- a/cmd/license/main.go +++ b/cmd/license/main.go @@ -12,6 +12,7 @@ import ( "text/template" "time" + "github.com/posener/complete" "within.website/x/cmd/license/licenses" "within.website/x/internal" ) @@ -33,6 +34,15 @@ func init() { fmt.Fprintln(os.Stderr, "\nBy default the name and email are scraped from `git config`") os.Exit(2) } + + var names []string + for name := range licenses.List { + names = append(names, name) + } + + sort.Strings(names) + + internal.HandleCompletion(complete.PredictSet(names...), nil) } func main() { diff --git a/docs/man1/ghstat.1 b/docs/man1/ghstat.1 deleted file mode 100644 index 694c72e..0000000 --- a/docs/man1/ghstat.1 +++ /dev/null @@ -1,75 +0,0 @@ -.Dd December 09, 2018 -.Dt GHSTAT 1 URM - - -.Sh NAME -.Nm ghstat -.Nd Look up and summarize the status of GitHub. - - -.Sh SYNOPSIS -.Nm -.Op Fl license -.Op Fl message - - - -.Sh DESCRIPTION -.Nm -is a small tool to help users look up information about -.Lk hyperlink: https://github.com GitHub -system status as viewed by their -.Lk hyperlink: https://status.github.com Status API -. - -By default this tool will print a very small summary of GitHub status followed by the time the last update was made in RFC 3339 time format. - -Here's an example: - -.Li $ ghstat -.Li Status: good (2018-12-06T17:09:57Z) - -.Bl -tag -width " " -offset indent -compact - -.It Fl license -If set, the tool will show its software license details and then exit. - -.It Fl message -If set, the tool will show the last status message from GitHub more verbosely like such: - -.Li $ ghstat -message -.Li Last message: -.Li Status: good -.Li Message: -.Li Time: - -When there is a message relevant to the status, it and its time will be shown here. - -.El - - -.Sh EXAMPLES - -.Li ghstat - -.Li ghstat -license - -.Li ghstat -message - - -.Sh DIAGNOSTICS - -.Ex -std ghstat - - -.Sh SEE ALSO - -.Bl -bullet - -.It -.Lk hyperlink: https://github.com GitHub - -.It -.Lk hyperlink: https://status.github.com GitHub Status - -.El @@ -47,9 +47,10 @@ require ( github.com/peterh/liner v1.1.0 github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 github.com/pkg/errors v0.8.1 + github.com/posener/complete v1.2.3 + github.com/posener/complete/v2 v2.0.1-alpha.12 github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/streamrail/concurrent-map v0.0.0-20160823150647-8bf1e9bacbf6 - github.com/stretchr/testify v1.3.0 // indirect github.com/sycamoreone/orc v0.0.0-20150204213357-1627eaec2699 github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b // indirect @@ -64,6 +64,10 @@ github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc h1:f8eY6cV/x1x+HLjOp4r72s/31/V2aTUtg5oKRRPf8/Q= github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f h1:1LkiAnH6RhOEbQAcfcEcixM5IsegqFi6IH0Nz0ZGqYs= github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f/go.mod h1:mQEoc766DxPTAwQ54neWTK/lFqIeSO7OU6bqZsceglw= github.com/jaytaylor/html2text v0.0.0-20190408195923-01ec452cbe43 h1:jTkyeF7NZ5oIr0ESmcrpiDgAfoidCBF4F5kJhjtaRwE= @@ -122,6 +126,12 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/posener/complete/v2 v2.0.1-alpha.12 h1:0wvkuDfHb5vSZlNBYgpEH4XQHpF46MjLPHav8XC77Nc= +github.com/posener/complete/v2 v2.0.1-alpha.12/go.mod h1://JlL91cS2JV7rOl6LVHrRqBXoBUecJu3ILQPgbJiMQ= +github.com/posener/script v1.0.4 h1:nSuXW5ZdmFnQIueLB2s0qvs4oNsUloM1Zydzh75v42w= +github.com/posener/script v1.0.4/go.mod h1:Rg3ijooqulo05aGLyGsHoLmIOUzHUVK19WVgrYBPU/E= github.com/sendgrid/rest v2.4.1+incompatible h1:HDib/5xzQREPq34lN3YMhQtMkdXxS/qLp5G3k9a5++4= github.com/sendgrid/rest v2.4.1+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE= github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf h1:pvbZ0lM0XWPBqUKqFU8cmavspvIl9nulOYwdy6IFRRo= @@ -132,6 +142,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/sycamoreone/orc v0.0.0-20150204213357-1627eaec2699 h1:sL7K4miTSRR8rb6FeDx/EKPS3g8dQcoRKaIcrzusZDI= github.com/sycamoreone/orc v0.0.0-20150204213357-1627eaec2699/go.mod h1:SZJ3/DVrJnKZPTTwCb38i9XZQU0T1yDm7oulSUO87a8= github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7SJEOqkIdNDGJXrQIhuIx9D2DBXjavSU= @@ -211,8 +223,11 @@ google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.0 h1:Tfd7cKwKbFRsI8RMAD3oqqw7JPFRrvFlOsfbgVkjOOw= google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/tucnak/telebot.v2 v2.0.0-20190415090633-8c1c512262f2 h1:wGFU+pn16CuaCt4lc9gkdF1R/y4M8CRi4g6yj7pxpBE= gopkg.in/tucnak/telebot.v2 v2.0.0-20190415090633-8c1c512262f2/go.mod h1:+//wyPtHTeW2kfyEBwB05Hqnxev7AGrsLIyylSH++KU= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= within.website/confyg v0.4.0 h1:FklkpJyMLYBxECCI4RS4R2c/x7PblOvbX0qBjk8Wkjs= within.website/confyg v0.4.0/go.mod h1:KD5rDgkE3B+vbDiH/usiuK+CfiOkCiuD87NEF3/budk= within.website/johaus v1.1.0 h1:j59k9LM5ue+CDwUZAJitYjek6i8ISMkkCFiVXKZLByw= diff --git a/internal/internal.go b/internal/internal.go index 1c78d60..e63f6f7 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -7,7 +7,9 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" + "github.com/posener/complete" "go4.org/legal" "within.website/confyg/flagconfyg" "within.website/ln" @@ -83,3 +85,23 @@ func HandleStartup() { func init() { http.DefaultTransport = useragent.Transport("within.website-x", "https://within.website/.x.botinfo", http.DefaultTransport) } + +func HandleCompletion(args complete.Predictor, subcommands complete.Commands) { + cmd := complete.Command{ + Flags: map[string]complete.Predictor{}, + Sub: subcommands, + Args: args, + } + + flag.CommandLine.VisitAll(func(fl *flag.Flag) { + cmd.Flags["-"+fl.Name] = complete.PredictAnything + + if fl.DefValue == "true" || fl.DefValue == "false" { + cmd.Flags["-"+fl.Name] = complete.PredictNothing + } + }) + + if complete.New(filepath.Base(os.Args[0]), cmd).Run() { + os.Exit(0) + } +} |
