Skip to content

Commit

Permalink
Merge pull request #2001 from dearchap/issue_1069
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap authored Nov 2, 2024
2 parents 30c4df2 + 8c6801f commit 0c4c199
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
7 changes: 7 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ type Argument interface {
Usage() string
}

// AnyArguments to differentiate between no arguments(nil) vs aleast one
var AnyArguments = []Argument{
&StringArg{
Max: -1,
},
}

type ArgumentBase[T any, C any, VC ValueCreator[T, C]] struct {
Name string `json:"name"` // the name of this argument
Value T `json:"value"` // the default value of this argument
Expand Down
3 changes: 2 additions & 1 deletion examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func ExampleCommand_Run_appHelp() {
Flags: []cli.Flag{
&cli.StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
},
Arguments: cli.AnyArguments,
Commands: []*cli.Command{
{
Name: "describeit",
Expand Down Expand Up @@ -202,7 +203,7 @@ func ExampleCommand_Run_noAction() {
// greet - A new cli application
//
// USAGE:
// greet [global options] [arguments...]
// greet [global options]
//
// GLOBAL OPTIONS:
// --help, -h show help
Expand Down
11 changes: 9 additions & 2 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ var (
SuggestCommand SuggestCommandFunc = suggestCommand
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
)
var AnyArguments = []Argument{
&StringArg{
Max: -1,
},
}
AnyArguments to differentiate between no arguments(nil) vs aleast one

var CommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}

Expand Down Expand Up @@ -84,7 +91,7 @@ var RootCommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}

USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}

VERSION:
{{.Version}}{{end}}{{end}}{{if .Description}}
Expand Down Expand Up @@ -112,7 +119,7 @@ var SubcommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}

USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleCommands}}[command [command options]] {{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]] {{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}}

CATEGORY:
{{.Category}}{{end}}{{if .Description}}
Expand Down
7 changes: 4 additions & 3 deletions help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func Test_Help_RequiredFlagsNoDefault(t *testing.T) {
Flags: []Flag{
&IntFlag{Name: "foo", Aliases: []string{"f"}, Required: true},
},
Writer: output,
Arguments: AnyArguments,
Writer: output,
}

_ = cmd.Run(buildTestContext(t), []string{"test", "-h"})
Expand Down Expand Up @@ -716,7 +717,7 @@ func TestShowSubcommandHelp_GlobalOptions(t *testing.T) {
foo frobbly
USAGE:
foo frobbly [command [command options]]
foo frobbly [command [command options]]
OPTIONS:
--bar value
Expand Down Expand Up @@ -1719,7 +1720,7 @@ func TestCategorizedHelp(t *testing.T) {
application
USAGE:
cli.test [global options] [arguments...]
cli.test [global options]
GLOBAL OPTIONS:
--help, -h show help
Expand Down
6 changes: 3 additions & 3 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cli
var (
helpNameTemplate = `{{$v := offset .FullName 6}}{{wrap .FullName 3}}{{if .Usage}} - {{wrap .Usage $v}}{{end}}`
argsTemplate = `{{if .Arguments}}{{range .Arguments}}{{.Usage}}{{end}}{{end}}`
usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleFlags}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{template "argsTemplate" .}}{{end}}{{end}}`
usageTemplate = `{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleFlags}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} {{template "argsTemplate" .}}{{end}}{{end}}{{end}}`
descriptionTemplate = `{{wrap .Description 3}}`
authorsTemplate = `{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
{{range $index, $author := .Authors}}{{if $index}}
Expand Down Expand Up @@ -45,7 +45,7 @@ var RootCommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
VERSION:
{{.Version}}{{end}}{{end}}{{if .Description}}
Expand Down Expand Up @@ -95,7 +95,7 @@ var SubcommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleCommands}}[command [command options]] {{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]] {{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}}
CATEGORY:
{{.Category}}{{end}}{{if .Description}}
Expand Down
11 changes: 9 additions & 2 deletions testdata/godoc-v3.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ var (
SuggestCommand SuggestCommandFunc = suggestCommand
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
)
var AnyArguments = []Argument{
&StringArg{
Max: -1,
},
}
AnyArguments to differentiate between no arguments(nil) vs aleast one

var CommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}

Expand Down Expand Up @@ -84,7 +91,7 @@ var RootCommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}

USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}

VERSION:
{{.Version}}{{end}}{{end}}{{if .Description}}
Expand Down Expand Up @@ -112,7 +119,7 @@ var SubcommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}

USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleCommands}}[command [command options]] {{end}}{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}}
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}}{{if .VisibleCommands}} [command [command options]] {{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Category}}

CATEGORY:
{{.Category}}{{end}}{{if .Description}}
Expand Down

0 comments on commit 0c4c199

Please sign in to comment.