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

Omitting a hyphen from long-arguments doesn't fail with extra arguments as it should #365

Open
dsoprea opened this issue Jun 25, 2021 · 0 comments

Comments

@dsoprea
Copy link

dsoprea commented Jun 25, 2021

This is my argument configuration:

type parameters struct {
	Filepath                string `short:"f" long:"filepath" required:"true" description:"File-path of image"`
	PrintAsJson             bool   `short:"j" long:"json" description:"Print out as JSON"`
	IsVerbose               bool   `short:"v" long:"verbose" description:"Print logging"`
	ThumbnailOutputFilepath string `short:"t" long:"thumbnail-output-filepath" description:"File-path to write thumbnail to (if present)"`
	DoNotPrintTags          bool   `short:"n" long:"no-tags" description:"Do not actually print tags. Good for auditing the logs or merely checking the EXIF structure for errors."`
	SkipBlocks              int    `short:"s" long:"skip" description:"Skip this many EXIF blocks before returning"`
	DoUniversalTagSearch    bool   `short:"u" long:"universal-tags" description:"If tags not found in known mapped IFDs, fallback to trying all IFDs."`
}

var (
	arguments = new(parameters)
)

...

func main() {

...

	_, err := flags.Parse(arguments)
	if err != nil {
		os.Exit(-1)
	}

...
}

If you accidentally pass -filepath instead of --filepath, two things should happen: 1) 'ilepath' should be taken as the argument and go-flags should fail due to the provided argument now being an extra. However, it parses successfully and returned control to the caller, just to fail due to it being an invalid file-path.

Both of these have the same result:

$ go run command/exif-read-tool/main.go -filepath 
Stack:

*fs.PathError open ilepath: no such file or directory
/home/dustin/go/src/github.com/dsoprea/go-exif/v3/command/exif-read-tool/main.go:92 (0x5cb7f7)
	main: log.PanicIf(err)
/usr/local/go/src/runtime/proc.go:225 (0x437cb6)
	main: fn()
/usr/local/go/src/runtime/asm_amd64.s:1371 (0x468041)
	goexit: BYTE	$0x90	// NOP

exit status 254

$ go run command/exif-read-tool/main.go -filepath assets/gps.jpg
Stack:

*fs.PathError open ilepath: no such file or directory
/home/dustin/go/src/github.com/dsoprea/go-exif/v3/command/exif-read-tool/main.go:92 (0x5cb7f7)
	main: log.PanicIf(err)
/usr/local/go/src/runtime/proc.go:225 (0x437cb6)
	main: fn()
/usr/local/go/src/runtime/asm_amd64.s:1371 (0x468041)
	goexit: BYTE	$0x90	// NOP

exit status 254

REF: dsoprea/go-exif#61

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

1 participant