Skip to content

Commit

Permalink
Argument validation
Browse files Browse the repository at this point in the history
  • Loading branch information
harrywhite4 committed Sep 4, 2018
1 parent 882ea4f commit 1e09ca4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ func processFile(file string) error {
return nil
}

func validateArgs() bool {
if quality < 0 || quality > 100 {
fmt.Println("Quality must be between 0 and 100")
return false
}

if targetPixels < 0 {
fmt.Println("Target pixels can not be negative")
return false
}

return true
}

func printHelp() {
usage := "compress path1 path2 ... [options]\n"
usageDescription := `Path can be an image file or a directory
Expand All @@ -201,6 +215,11 @@ func main() {
os.Exit(1)
}

valid := validateArgs()
if !valid {
os.Exit(1)
}

positionals := flagSet.Args()
if len(positionals) == 0 {
fmt.Println("No path specified")
Expand Down

0 comments on commit 1e09ca4

Please sign in to comment.