Skip to content

Instantly share code, notes, and snippets.

@suntong
Created August 2, 2015 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suntong/399055da253a65ac79be to your computer and use it in GitHub Desktop.
Save suntong/399055da253a65ac79be to your computer and use it in GitHub Desktop.
$ easygen test/commandlineFlag
package easygenapi
import (
"flag"
"fmt"
"os"
)
////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
const progname = "easygen" // os.Args[0]
// The Options struct defines the structure to holds the commandline values
type Options struct {
HTML bool // treat the template file as html instead of text
TemplateStr string // template string (in text)
TemplateFile string // .tmpl template file name (default: same as .yaml file)
debug int // debugging level
}
////////////////////////////////////////////////////////////////////////////
// Global variables definitions
// Opts holds the actual values from the command line paramters
var Opts Options
////////////////////////////////////////////////////////////////////////////
// Commandline definitions
func init() {
flag.BoolVar(&Opts.HTML, "html", false,
"treat the template file as html instead of text")
flag.StringVar(&Opts.TemplateStr, "ts", "",
"template string (in text)")
flag.StringVar(&Opts.TemplateFile, "tf", "",
".tmpl template file name (default: same as .yaml file)")
flag.IntVar(&Opts.debug, "debug", 0,
"debugging level")
}
// The Usage function shows help on commandline usage
func Usage() {
fmt.Fprintf(os.Stderr,
"nUsage:n %s [flags] YamlFileNamennFlags:nn",
progname)
flag.PrintDefaults()
fmt.Fprintf(os.Stderr,
"nYamlFileName: The name for the .yaml data and .tmpl template filentOnly the name part, without extension. Can include the path as well.n")
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment