Command Line Option Parser

When I first  began learning Go, I needed a better way to parse the command line options.  The Go package flag contains a comprehensive package for parsing command line options that traps errors and provides a help facility.  For most of my quick-n-dirty programming, I needed something more simple.  So I wrote clop (Command Line Option Parser).

Clop is not intended to be a replacement for Go flag.  Instead it is a meant for simple programs and Go newbs like myself.  It requires no setup; just import it and you are ready to access options, flags and arguments.

Here is a small example:

package main
import	"fmt"
import	op ""
func main () {
  switch {
    case op.Flag("h"):
      fmt.Println("This program does nothing at all. Have a nice day.")
    fmt.Println("Usage: mycmd [options]\nUse -h for more help")

View Source


Leave a Reply

Your email address will not be published. Required fields are marked *