Skip to content

Fix improper whitespace formatting in usageTemplate variable#1946

Closed
lattn wants to merge 0 commit into
urfave:v2-maintfrom
lattn:v2-maint
Closed

Fix improper whitespace formatting in usageTemplate variable#1946
lattn wants to merge 0 commit into
urfave:v2-maintfrom
lattn:v2-maint

Conversation

@lattn

@lattn lattn commented Jul 6, 2024

Copy link
Copy Markdown

just fix usageTemplate variable in template.go

@lattn
lattn requested a review from a team as a code owner July 6, 2024 14:20
@bartekpacia

Copy link
Copy Markdown
Member

Hi, thanks for the contribution!

Could you show a comparison of before/after?

@lattn

lattn commented Jul 6, 2024

Copy link
Copy Markdown
Author
// 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]

@Juneezee Juneezee left a comment

Copy link
Copy Markdown
Member

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}}

@lattn

lattn commented Jul 7, 2024

Copy link
Copy Markdown
Author

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

dearchap commented Jul 7, 2024

Copy link
Copy Markdown
Contributor

@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

dearchap commented Jul 7, 2024

Copy link
Copy Markdown
Contributor

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