cli icon indicating copy to clipboard operation
cli copied to clipboard

Nitpicking on consistency with dashes for Flags

Open jurisbu opened this issue 3 years ago • 1 comments

Is it expected that flags in command help output and error messages are inconsistent in terms of dash count to used?

Bare in mind these are my first steps with this wonderful library, I went over the manual and just tried some simple toy tools to get the feel. And this sort of caught my eye.

Suppose I have a very simple CLI application that defined a required flag conf:

package main

import (
	"fmt"
	"log"
	"os"

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

func main() {
	app := &cli.App{
		Name:  "hello",
		Usage: "Just hello",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     "conf",
				Required: true,
				Value:    "",
			},
		},
		Action: func(*cli.Context) error {
			fmt.Println("Hello ...")
			return nil
		},
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}

As a user when I execute cli application without flags I get two hints regarding required option:

$ ./hello
NAME:
   hello - Just hello

USAGE:
   hello [global options] command [command options] [arguments...]

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

GLOBAL OPTIONS:
   --conf value                                   !!! HINT #1
   --help, -h    show help (default: false)
2022/01/10 14:38:43 Required flag "conf" not set  !!! HINT #2

OK, so far. I can work with it. So, I must pass in a "conf" flag which probably means specifying --conf.

Alright...

$ ./hello --conf
Incorrect Usage. flag needs an argument: -conf

NAME:
   hello - Just hello

USAGE:
   hello [global options] command [command options] [arguments...]

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

GLOBAL OPTIONS:
   --conf value  
   --help, -h    show help (default: false)
2022/01/10 14:46:56 flag needs an argument: -conf

Hmmmm ... well I suppose it does not really matter if one uses GNU-style long flags with double dashes or a single dash flags. But the consistency!!!

Again, sorry if this is nitpicking, just a cosmetic issue I suppose.

jurisbu avatar Jan 10 '22 12:01 jurisbu

@jurisbu That is actually the error in a standard format returned by the golang flag library. The name of the flag is conf so it returns the error like that.

dearchap avatar Sep 15 '22 18:09 dearchap

Can't fix at this time. Closing

dearchap avatar Oct 17 '22 11:10 dearchap