Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
update usage handler and handle no args
Browse files Browse the repository at this point in the history
  • Loading branch information
Pallav Jha authored and craigmulligan committed Jan 19, 2020
1 parent d0a8281 commit dcba083
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sandy.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,28 @@ func (i *arrayFlags) Set(value string) error {
return nil
}

// sandyUsage func is the usage handler for the sandy command
func sandyUsage() {
fmt.Printf("Usage: %s [OPTIONS] command\n", os.Args[0])
flag.PrintDefaults()
}

func main() {
var allowedPattern arrayFlags
var blockedPattern arrayFlags

// TODO add sane defaults like libc etc
allowedPattern = append(allowedPattern, "")

flag.Var(&allowedPattern, "y", "A glob pattern for automatically allowing file reads.")
flag.Var(&blockedPattern, "n", "A glob pattern for automatically blocking file reads.")
help := flag.Bool("h", false, "Print Usage.")
// overriding the Usage handler
flag.Usage = sandyUsage
flag.Var(&blockedPattern, "n", "A glob pattern for automatically blocking file reads.\nFor example, \"/etc/password.txt\" or \"*.txt\".")
flag.Var(&allowedPattern, "y", "A glob pattern for automatically allowing file reads.\nExpected format is same as -n.")
showHelp := flag.Bool("h", false, "Print Usage.")

flag.Parse()

if *help == true {
if flag.NArg() < 1 || *showHelp {
flag.Usage()
return
}
Expand Down

0 comments on commit dcba083

Please sign in to comment.