mirror of https://github.com/knative/client.git
Wrap flag usage to terminal size (#351)
* Wrap flag usage to terminal size * Revert downgraded deps * New vendored files I missed before
This commit is contained in:
parent
284238d4f6
commit
260411724c
1
go.mod
1
go.mod
|
|
@ -28,6 +28,7 @@ require (
|
||||||
github.com/spf13/cobra v0.0.3
|
github.com/spf13/cobra v0.0.3
|
||||||
github.com/spf13/pflag v1.0.3
|
github.com/spf13/pflag v1.0.3
|
||||||
github.com/spf13/viper v1.3.1
|
github.com/spf13/viper v1.3.1
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import (
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
homedir "github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"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/gcp"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
|
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
|
||||||
)
|
)
|
||||||
|
|
@ -140,6 +141,14 @@ func NewKnCommand(params ...commands.KnParams) *cobra.Command {
|
||||||
// Deal with empty and unknown sub command groups
|
// Deal with empty and unknown sub command groups
|
||||||
EmptyAndUnknownSubCommands(rootCmd)
|
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.
|
// For glog parse error.
|
||||||
flag.CommandLine.Parse([]string{})
|
flag.CommandLine.Parse([]string{})
|
||||||
|
|
||||||
|
|
@ -256,3 +265,8 @@ func removeKnPluginFlags(args []string) []string {
|
||||||
|
|
||||||
return remainingArgs
|
return remainingArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func width() (int, error) {
|
||||||
|
width, _, err := terminal.GetSize(int(os.Stdout.Fd()))
|
||||||
|
return width, err
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue