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

Error customization #85

Open
silvioprog opened this issue Aug 21, 2022 · 1 comment
Open

Error customization #85

silvioprog opened this issue Aug 21, 2022 · 1 comment

Comments

@silvioprog
Copy link

silvioprog commented Aug 21, 2022

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

@codenoid
Copy link

codenoid commented Apr 23, 2024

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

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

No branches or pull requests

2 participants