Пример #1
0
// ExecuteHelpTemplate() prints the command line help using the given template and exits.
func executeHelpTemplate(errMsg string) {
	buff := bytes.Buffer{}
	flag.VisitAll(func(f *flag.Flag) {
		buff.WriteString(fmt.Sprintf("\t-%-8s%s\n", f.Name, f.Usage))
	})

	data := struct {
		BuildInfo string
		Flags     string
		Error     string
	}{
		core.BuildInfo(),
		buff.String(),
		errMsg,
	}

	t, _ := template.New("help").Parse(helpTemplate)
	t.Execute(os.Stdout, data)

	os.Exit(1)
}
Пример #2
0
func main() {
	opts := config()
	if opts.PrintHelp {
		executeHelpTemplate("")
	} else if opts.PrintVersion {
		fmt.Println(core.BuildInfo())
		os.Exit(0)
	}

	switch opts.Mode {
	case "cli":
		if anyEmptyString(opts.InFile, opts.OutFile, opts.ThumbType) {
			executeHelpTemplate("Missing InFile, OutFile, or ThumbType.")
		}
		if !inArrayString(opts.ThumbType, core.ValidThumbTypes) {
			executeHelpTemplate("Invalid thumbnail type.")
		}
		cli.Go()
	case "http":
		http.Go()
	default:
		executeHelpTemplate("Invalid mode.")
	}
}