apps-cli-plugin icon indicating copy to clipboard operation
apps-cli-plugin copied to clipboard

Format breaks in --help output if there's >1 Example command

Open heyjcollins opened this issue 2 years ago • 1 comments

  • [X] I reviewed open and closed Github issues that may be related to my problem.
  • [X] I am reporting a bug that others will be able to reproduce.

Describe the bug

if there are two or more example commands included in the help, only the first command is indented. all the example commands should be indented

Expected behavior

all the example commands in help should be indented

Steps to Reproduce

  1. download and install the appstack cli commands plugin
  2. execute tanzu apps workload create -h
  3. notice the indentation for the second and third examples:
$ tanzu apps workload create -h
Create a workload with specified configuration.

Workload configuration options include:
- source code to build
- runtime resource limits
- environment variables
- services to bind

Usage:
    tanzu apps workload create [name] [flags]

Examples:
    tanzu apps workload create my-workload --git-repo https://example.com/my-workload.git
tanzu apps workload create my-workload --local-path . --source-image registry.example/repository:tag
tanzu apps workload create --file workload.yaml

...

Version (Apps plugin version, Version of K8s running on cluster)

Put the output of the following commad

tanzu version && tanzu apps version

Environment where the bug was observed (cloud, OS, etc)

Plugin version: apps:v0.5.1 k8s version (server): GitVersion:"v1.23.3+vmware.1" MacOS, Docker Desktop

Originally submitted by

@codegold79

heyjcollins avatar Mar 17 '22 01:03 heyjcollins

From the tanzu-core-cli team, a possible solution:

The formatting of the help output is done by the tanzu-plugin-runtime library, which is maintained by the CLI Core team. You can see the (very recently adjusted) code here. For examples, because it is a multiline single string that Cobra receives, it cannot do indentation. You must do it yourself as you originally thought. Cobra will do the indentation for the first line. This is useful for cases where the example is a single line. When dealing with a multiline example, you may want to use Go's back quote ` .

The example solution provide to us is: So the code would become

fmt.Sprintf(`%[1]s list
  %[1]s list --output yaml`, c.Name)

Line breaks and spaces are respected with back quotes. Note their use of %[#]s format.

bbtong avatar Oct 05 '23 21:10 bbtong