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

Fix improper whitespace formatting in usageTemplate variable #1946

Closed
wants to merge 0 commits into from

Conversation

caeret
Copy link

@caeret caeret commented Jul 6, 2024

just fix usageTemplate variable in template.go

@caeret caeret requested a review from a team as a code owner July 6, 2024 14:20
@bartekpacia
Copy link
Member

Hi, thanks for the contribution!

Could you show a comparison of before/after?

@caeret
Copy link
Author

caeret commented Jul 6, 2024

// test.go
package main

import (
	"os"

	cli "github.com/urfave/cli/v2"
)

func main() {
	app := cli.NewApp()
	app.ArgsUsage = "[arg1]"
	app.Commands = []*cli.Command{
		{
			Name:      "cmd1",
			ArgsUsage: "[arg2]",
			Action: func(cctx *cli.Context) error {
				return nil
			},
		},
	}
	err := app.Run(os.Args)
	if err != nil {
		panic(err)
	}
}

go run test.go -h will print:

NAME:
   test - A new cli application

USAGE:
   test [global options] command [command options] [arg1]

COMMANDS:
   cmd1
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h  show help

but go run test.go cmd1 -h will print:

NAME:
   test cmd1

USAGE:
   test cmd1 [command options][arg2]

OPTIONS:
   --help, -h  show help

difference

there is no space between comand options and custom args usage.

   test [global options] command [command options] [arg1]

vs

   test cmd1 [command options][arg2]

Copy link
Member

@Juneezee Juneezee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SubcommandHelpTemplate seems to have the same whitespace problem too. Would you mind taking a look as well?

cli/template.go

Lines 82 to 86 in 84c536d

var SubcommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}{{if .Description}}

@caeret
Copy link
Author

caeret commented Jul 7, 2024

The SubcommandHelpTemplate seems to have the same whitespace problem too. Would you mind taking a look as well?

cli/template.go

Lines 82 to 86 in 84c536d

var SubcommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}{{if .Description}}

I'm sorry that when modifying the code today, I missed some variables related to ArgsUsage for the sake of convenience in using the vim editor. The whitespace issue in the SubcommandHelpTemplate variable has now been fixed, and running 'go test ./...' shows no problems.

@dearchap
Copy link
Contributor

dearchap commented Jul 7, 2024

@caeret Sorry looks like I messed up the commit by force pushing v2-maint to your repo. . Can you repush your PR ? Also run "make docs" and "make v2approve"

@dearchap
Copy link
Contributor

dearchap commented Jul 7, 2024

Closed by mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants