flaggy icon indicating copy to clipboard operation
flaggy copied to clipboard

Error customization

Open silvioprog opened this issue 2 years ago • 1 comments

Hi.

Consider the following example:

package main

import "github.com/integrii/flaggy"

func main() {
	// Declare variables and their defaults
	var stringFlag = "defaultValue"

	// Create the subcommand
	subcommand := flaggy.NewSubcommand("subcommandExample")

	// Add a flag to the subcommand
	subcommand.String(&stringFlag, "f", "flag", "A test string flag")

	// Add the subcommand to the parser at position 1
	flaggy.AttachSubcommand(subcommand, 1)

	// Parse the subcommand and all flags
	flaggy.Parse()

	// Use the flag
	println(stringFlag)
}

when calling this by % ./main -f a, it shows the following error:

mymain

  Usage:
    mymain [subcommandExample]

  Subcommands: 
    subcommandExample

  Flags: 
       --version   Displays the program version string.
    -h --help      Displays help with available flag, subcommand, and positional value parameters.

Unknown arguments supplied:  f a

so, is there any option to show the error as Unknown arguments supplied: -f a instead of Unknown arguments supplied: f a? I.e, replacing the empty space before f by the - symbol.

Edit: the same for Expected a following arg for flag f, but it did not exist, it would be nice an option to show Expected a following arg for flag -f, but it did not exist instead, and Expected a following arg for flag --flag, but it did not exist instead of Expected a following arg for flag flag, but it did not exist, and so on.

TIA

silvioprog avatar Aug 21 '22 18:08 silvioprog

it should be called like this: ./main f <value>, if you want a flag, try

flaggy.String(&stringFlag, "f", "flong", "desc")

then you can use ./main -f <value> command

codenoid avatar Apr 23 '24 05:04 codenoid