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

cli parsing: warn on failed parsing #792

Open
bjohas opened this issue Nov 19, 2016 · 1 comment
Open

cli parsing: warn on failed parsing #792

bjohas opened this issue Nov 19, 2016 · 1 comment

Comments

@bjohas
Copy link

bjohas commented Nov 19, 2016

It seems that sometimes drive fails silently, e.g. if the command line switches aren't correct, e.g. see here #791.

Could there always be a warning if the execution didn't work? (I.e. just a script level failure, not at API level failure.)

@odeke-em odeke-em changed the title Silent failure cli parsing: warn on failed parsing Nov 24, 2016
@odeke-em
Copy link
Owner

Unfortunately, short of writing my own commandline parser this won't be something to easily detect.
Here is a sample program at https://play.golang.org/p/NEgNeUVMcb

package main

import (
	"flag"
	"fmt"
)

func main() {
	var name, season string
var verbose bool

	flag.StringVar(&name, "name", "default-name", "the name to set")
	flag.StringVar(&season, "season", "winter", "the current season")
flag.BoolVar(&verbose, "verbose", false, "the verbosity")
	flag.Parse()

	fmt.Printf("name: %s\nprogram: %s\nverbosity: %v", name, season, verbose)
}

when run:

arguments well provided

$ go run main.go --verbose  --name drive
name: drive
program: winter
verbosity: true

misplaced arguments

$ go run main.go --verbose few ones --name drive
name: default-name
program: winter

as you can see, using stdlib package flag to accomodate the request would require creating a new module entirely

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