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

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

Open
2 tasks done
heyjcollins opened this issue Mar 17, 2022 · 1 comment
Open
2 tasks done

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

heyjcollins opened this issue Mar 17, 2022 · 1 comment
Assignees
Labels
accepted blocked bug Something isn't working MIGRATED-MIGRATED Migrated to private repo

Comments

@heyjcollins
Copy link
Contributor

  • I reviewed open and closed Github issues that may be related to my problem.
  • 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 heyjcollins added bug Something isn't working needs-triage labels Mar 17, 2022
@atmandhol atmandhol added this to the 0.6.0 milestone Mar 31, 2022
@warango4 warango4 self-assigned this Apr 1, 2022
@atmandhol atmandhol modified the milestones: 0.6.0, 0.7.0 Apr 5, 2022
@atmandhol atmandhol removed this from the 0.7.0 milestone Apr 28, 2022
@bbtong
Copy link

bbtong commented Oct 5, 2023

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.

@heyjcollins heyjcollins added the MIGRATED-MIGRATED Migrated to private repo label Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted blocked bug Something isn't working MIGRATED-MIGRATED Migrated to private repo
Projects
None yet
Development

No branches or pull requests

4 participants