You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2022/04/28 07:36:39 UTC
[camel-k] 01/04: fix(cli): format long subcommand descriptions
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 257c060b405ef54c617f885f41da35957e509ec4
Author: Kuthumi Pepple <ku...@gmail.com>
AuthorDate: Fri Apr 22 10:57:28 2022 +0100
fix(cli): format long subcommand descriptions
---
go.mod | 1 +
pkg/cmd/root.go | 14 ++++++++++++++
2 files changed, 15 insertions(+)
diff --git a/go.mod b/go.mod
index 751153992..540a92026 100644
--- a/go.mod
+++ b/go.mod
@@ -44,6 +44,7 @@ require (
go.uber.org/zap v1.21.0
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
+ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
gopkg.in/inf.v0 v0.9.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.22.5
diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go
index a01a02a5d..44d198a24 100644
--- a/pkg/cmd/root.go
+++ b/pkg/cmd/root.go
@@ -26,6 +26,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
+ "golang.org/x/term"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -83,6 +84,11 @@ func kamelPreAddCommandInit(options *RootCmdOptions) *cobra.Command {
cmd.PersistentFlags().StringVar(&options.KubeConfig, "kube-config", os.Getenv("KUBECONFIG"), "Path to the kube config file to use for CLI requests")
cmd.PersistentFlags().StringVarP(&options.Namespace, "namespace", "n", "", "Namespace to use for all operations")
+ cobra.AddTemplateFunc("wrappedFlagUsages", wrappedFlagUsages)
+ usageTmpl := cmd.UsageTemplate()
+ usageTmpl = strings.Replace(usageTmpl, ".LocalFlags.FlagUsages", " wrappedFlagUsages .", 1)
+ cmd.SetUsageTemplate(usageTmpl)
+
return &cmd
}
@@ -237,3 +243,11 @@ func (command *RootCmdOptions) GetCamelCmdClient() (*v1.CamelV1Client, error) {
func (command *RootCmdOptions) NewCmdClient() (client.Client, error) {
return client.NewOutOfClusterClient(command.KubeConfig)
}
+
+func wrappedFlagUsages(cmd *cobra.Command) string {
+ width := 80
+ if w, _, err := term.GetSize(0); err == nil {
+ width = w
+ }
+ return cmd.Flags().FlagUsagesWrapped(width - 1)
+}