Simple package for validating file and directory existence, eg. input to CLI applications. Originally built for go-arg - Pull request. The pull request was not accepted as go-arg is to be kept minimal, so this is extracted to a separate package. The usage is of course not limited to CLI application input, it is general purpose, but was built with CLI input in mind.
$ go get github.com/walle/fval
// CLI application with usage: example INPUTFILE OUTPUTDIR
if !fval.FileExists(os.Args[1]) {
fmt.Fprintf(os.Stderr, "Usage error: %s is not a valid file", os.Args[1])
os.Exit(1)
}
fval.DirExistsOrCreate(os.Args[2], 0766)
Use the go test
tool.
$ go test -cover
All contributions are welcome! See CONTRIBUTING for more info.
The code is under the MIT license. See LICENSE for more information.