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

AppHelpTemplate does not work under having required Flag and not having subcommand #1591

Closed
3 tasks done
yyamanoi1222 opened this issue Nov 20, 2022 · 6 comments · Fixed by #1608
Closed
3 tasks done
Labels
area/v2 relates to / is being considered for v2 area/v3 relates to / is being considered for v3 kind/bug describes or fixes a bug status/triage maintainers still need to look into this status/waiting-for-response Waiting for response from original requester

Comments

@yyamanoi1222
Copy link
Member

My urfave/cli version is

v2.23.5

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

My apologies if this is an existing issue.
AppHelpTemplate does not work under having required Flag and not having subcommand

To reproduce

main.go

package main

import (
  "github.com/urfave/cli/v2"
  "os"
  "fmt"
)

func main() {
  cli.AppHelpTemplate = ``
  app := cli.App{
    Name: "test app",
    Action: func(ctx *cli.Context) error {
      return nil
    },
    Flags: []cli.Flag{
      &cli.StringFlag{
        Name: "test",
        Required: true,
      },
    },
  }
  if err := app.Run(os.Args); err != nil {
    fmt.Printf("error %s", err)
  }
}

Observed behavior

$ go run main.go
NAME:
   test app - A new cli application

USAGE:
   test app command [command options] [arguments...]

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

OPTIONS:
   --test value  
   --help, -h    show help (default: false)
error Required flag "test" not set%                                                                                                                                                                                                                                                                                          
yamaoni% go run main.go                                                                                                                                                                                                                                                             [HEAD ~/ghq/github.com/yamanoi/cli-test]
NAME:
   test app - A new cli application

USAGE:
   test app command [command options] [arguments...]

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

OPTIONS:
   --test value  
   --help, -h    show help (default: false)
error Required flag "test" not set%

Expected behavior

$ go run main.go
error Required flag "test" not set%

Additional context

If I putsgo run main.go -h, the output is expected behavior

$ go run main.go -h

Want to fix this yourself?

yes

Run go version and paste its output here

go version go1.18.4 linux/amd64
@yyamanoi1222 yyamanoi1222 added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Nov 20, 2022
@dearchap
Copy link
Contributor

Duplicate of #1247

@dearchap dearchap marked this as a duplicate of #1247 Nov 28, 2022
@dearchap
Copy link
Contributor

@yyamanoi1222 Would you like to submit a fix for this ?

@yyamanoi1222
Copy link
Member Author

@dearchap Sorry, I must have missed it.
I'd like to submit a PR

@yyamanoi1222
Copy link
Member Author

yyamanoi1222 commented Dec 1, 2022

@dearchap
I think that my issue is slightly different from issue #1247.
I think that issue #1247 is caused by checkHelp slipping through when executing the help command.
My issue is that when executing the root command not a executing help, a SubcommandHelpTemplate is drawn instead of the AppHelpTemplate if a required parameter is missing.

If my perception is different, feel free to tell me.

@yyamanoi1222
Copy link
Member Author

so I think that the thing i have to is that changing
this method call to drawing appropriate help template by ctx

@dearchap
Copy link
Contributor

dearchap commented Dec 1, 2022

@yyamanoi1222 Can you check if the PR fixes your issue ?

@dearchap dearchap added area/v3 relates to / is being considered for v3 status/waiting-for-response Waiting for response from original requester labels Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 area/v3 relates to / is being considered for v3 kind/bug describes or fixes a bug status/triage maintainers still need to look into this status/waiting-for-response Waiting for response from original requester
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants