Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap flag usage to terminal size #351

Merged
merged 3 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.3.1 // indirect
sixolet marked this conversation as resolved.
Show resolved Hide resolved
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.3.0 // indirect
github.com/google/go-containerregistry v0.0.0-20190723205234-74f764b9c575 // indirect
github.com/google/go-containerregistry v0.0.0-20190623150931-ca8b66cb1b79 // indirect
github.com/google/gofuzz v1.0.0 // indirect
github.com/googleapis/gnostic v0.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/json-iterator/go v1.1.6 // indirect
sixolet marked this conversation as resolved.
Show resolved Hide resolved
github.com/knative/build v0.7.0 // indirect
github.com/knative/pkg v0.0.0-20190617142447-13b093adc272
github.com/knative/serving v0.6.0
Expand All @@ -28,7 +29,8 @@ require (
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.1
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
sixolet marked this conversation as resolved.
Show resolved Hide resolved
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand All @@ -37,7 +39,7 @@ require (
k8s.io/apimachinery v0.0.0-20190221084156-01f179d85dbc
k8s.io/cli-runtime v0.0.0-20190325194458-f2b4781c3ae1
k8s.io/client-go v0.0.0-20190226174127-78295b709ec6
k8s.io/kube-openapi v0.0.0-20190722073852-5e22f3d471e6 // indirect
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect
knative.dev/test-infra v0.0.0-20190730202142-17f2331e80ad
sigs.k8s.io/yaml v1.1.0
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,22 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekf
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-containerregistry v0.0.0-20190623150931-ca8b66cb1b79 h1:iObax0KHGJG3zG66UocaycSspWe9P7OT0SA9dL759sM=
github.com/google/go-containerregistry v0.0.0-20190623150931-ca8b66cb1b79/go.mod h1:yZAFP63pRshzrEYLXLGPmUt0Ay+2zdjmMN1loCnRLUk=
github.com/google/go-containerregistry v0.0.0-20190723205234-74f764b9c575 h1:ftd0T3Vm1eHYBeX57PFeXjoLaIHsTZj9qCF4gOHF4pA=
github.com/google/go-containerregistry v0.0.0-20190723205234-74f764b9c575/go.mod h1:yZAFP63pRshzrEYLXLGPmUt0Ay+2zdjmMN1loCnRLUk=
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/googleapis/gnostic v0.0.0-20170426233943-68f4ded48ba9/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.3.0 h1:CcQijm0XKekKjP/YCz28LXVSpgguuB+nCxaSjCe09y0=
github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
Expand All @@ -56,6 +61,8 @@ github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down Expand Up @@ -121,6 +128,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
Expand Down
14 changes: 14 additions & 0 deletions pkg/kn/core/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"golang.org/x/crypto/ssh/terminal"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
)
Expand Down Expand Up @@ -139,6 +140,14 @@ func NewKnCommand(params ...commands.KnParams) *cobra.Command {
// Deal with empty and unknown sub command groups
EmptyAndUnknownSubCommands(rootCmd)

// Wrap usage.
w, err := width()
if err == nil {
newUsage := strings.ReplaceAll(rootCmd.UsageTemplate(), "FlagUsages ",
fmt.Sprintf("FlagUsagesWrapped %d ", w))
rootCmd.SetUsageTemplate(newUsage)
}

// For glog parse error.
flag.CommandLine.Parse([]string{})

Expand Down Expand Up @@ -243,3 +252,8 @@ func removeKnPluginFlags(args []string) []string {

return remainingArgs
}

func width() (int, error) {
width, _, err := terminal.GetSize(int(os.Stdout.Fd()))
return width, err
}
5 changes: 3 additions & 2 deletions vendor/github.com/golang/protobuf/proto/properties.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/json-iterator/go/adapter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions vendor/github.com/json-iterator/go/go.mod

This file was deleted.

14 changes: 0 additions & 14 deletions vendor/github.com/json-iterator/go/go.sum

This file was deleted.

25 changes: 12 additions & 13 deletions vendor/github.com/json-iterator/go/iter_skip.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions vendor/github.com/json-iterator/go/reflect_native.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions vendor/github.com/json-iterator/go/stream_float.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/golang.org/x/net/http2/transport.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ github.com/gogo/protobuf/proto
github.com/gogo/protobuf/sortkeys
# github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/glog
# github.com/golang/protobuf v1.3.2
# github.com/golang/protobuf v1.3.1
github.com/golang/protobuf/proto
github.com/golang/protobuf/ptypes/any
github.com/golang/protobuf/ptypes
Expand All @@ -29,7 +29,7 @@ github.com/google/go-cmp/cmp/internal/diff
github.com/google/go-cmp/cmp/internal/flags
github.com/google/go-cmp/cmp/internal/function
github.com/google/go-cmp/cmp/internal/value
# github.com/google/go-containerregistry v0.0.0-20190723205234-74f764b9c575
# github.com/google/go-containerregistry v0.0.0-20190623150931-ca8b66cb1b79
github.com/google/go-containerregistry/pkg/name
# github.com/google/gofuzz v1.0.0
github.com/google/gofuzz
Expand Down Expand Up @@ -58,7 +58,7 @@ github.com/hashicorp/hcl/json/token
github.com/imdario/mergo
# github.com/inconshreveable/mousetrap v1.0.0
github.com/inconshreveable/mousetrap
# github.com/json-iterator/go v1.1.7
# github.com/json-iterator/go v1.1.6
github.com/json-iterator/go
# github.com/knative/build v0.7.0
github.com/knative/build/pkg/apis/build/v1alpha1
Expand Down Expand Up @@ -120,7 +120,7 @@ github.com/spf13/pflag
github.com/spf13/viper
# golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/crypto/ssh/terminal
# golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
# golang.org/x/net v0.0.0-20190628185345-da137c7871d7
golang.org/x/net/http2
golang.org/x/net/http/httpguts
golang.org/x/net/http2/hpack
Expand Down Expand Up @@ -391,7 +391,7 @@ k8s.io/client-go/listers/settings/v1alpha1
k8s.io/client-go/listers/storage/v1
k8s.io/client-go/listers/storage/v1alpha1
k8s.io/client-go/listers/storage/v1beta1
# k8s.io/kube-openapi v0.0.0-20190722073852-5e22f3d471e6
# k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208
k8s.io/kube-openapi/pkg/util/proto
# knative.dev/test-infra v0.0.0-20190730202142-17f2331e80ad
knative.dev/test-infra/scripts
Expand Down