1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
// {{.Name}} - {{.Desc}}
//
// {{.Text}}
package {{$.PackageName}}
{{template "header" $ }}
import (
// "fmt"
// "os"
// "github.com/go-easygen/go-flags"
)
// Template for main starts here
//////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
////////////////////////////////////////////////////////////////////////////
// Global variables definitions
// var (
// progname = "{{.Name}}"
// version = "0.1.0"
// date = "{{ date "I" }}"
// // opts store all the configurable options
// opts optsT
// )
//
// var gfParser = flags.NewParser(&opts, flags.Default)
////////////////////////////////////////////////////////////////////////////
// Function definitions
//==========================================================================
// Function main
// func main() {
{{- if .Version }}
// opts.Version = showVersion
{{- end }}
{{- if .Verbose }}
// opts.Verbflg = func() {
// opts.Verbose++
// }
{{- end }}
//
// if _, err := gfParser.Parse(); err != nil {
// fmt.Println()
// gfParser.WriteHelp(os.Stdout)
// os.Exit(1)
// }
// fmt.Println()
// //Do{{stringsTitle .Name}}()
// }
//
// //==========================================================================
// // support functions
//
{{- if .Version }}
// func showVersion() {
// fmt.Fprintf(os.Stderr, "{{.Name}} - {{.Desc}}, version %s\n", version)
// fmt.Fprintf(os.Stderr, "Built on %s\n", date)
// fmt.Fprintf(os.Stderr, "Copyright (C) {{$.Since}}-{{ date "Y4" }}, {{or $.Authors "The Author(s) <they@their.org>"}}\n\n")
// fmt.Fprintf(os.Stderr, "{{.Text}}\n")
// os.Exit(0)
// }
{{- end }}
// Template for main ends here
// Do{{stringsTitle .Name}} implements the business logic of command `{{.Name}}`
// func Do{{stringsTitle .Name}}() error {
// return nil
// }
// Template for type define starts here
{{template "type_struct" argsm "ProgramName" .ProgramName "Options" .Options "Verbose" .Verbose "Version" .Version "typeName" "optsT" "Prefix" "" }}
// Template for type define ends here
{{range .Command}}
// Template for "{{.Name}}" CLI handling starts here
{{template "header" $ }}
// package {{$.PackageName}}
// import (
// "fmt"
// "os"
//
// "github.com/go-easygen/go-flags/clis"
// )
// *** Sub-command: {{.Name}} ***
////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
{{template "type_struct" argsm "ProgramName" $.ProgramName "Options" .Options "typeName" (print (stringsTitle .Name) "Command") "Prefix" "// " }}
//
// var {{.Name}}Command {{stringsTitle .Name}}Command
//
// ////////////////////////////////////////////////////////////////////////////
// // Function definitions
//
// func init() {
// gfParser.AddCommand("{{.Name}}",
// "{{.Desc}}",
// "{{.Text}}",
// &{{.Name}}Command)
// }
//
// func (x *{{stringsTitle .Name}}Command) Execute(args []string) error {
// fmt.Fprintf(os.Stderr, "{{.Desc}}\n")
// // fmt.Fprintf(os.Stderr, "Copyright (C) {{$.Since}}-{{ date "Y4" }}, {{or $.Authors "The Author(s) <they@their.org>"}}\n\n")
// clis.Setup("{{$.Name}}::{{.Name}}", opts.Verbose)
// clis.Verbose(1, "Doing {{stringsTitle .Name}}, with %+v, %+v", opts, args)
// {{$opts := .Options}}// fmt.Println({{range $i, $opt := .Options}}x.{{$opt.Name}}{{if lt $i ($opts | len | minus1)}}, {{end}}{{end}})
// return x.Exec(args)
// }
//
// // Exec implements the business logic of command `{{.Name}}`
// func (x *{{stringsTitle .Name}}Command) Exec(args []string) error {
// // err := ...
// // clis.WarnOn("{{.Name}}::Exec", err)
// // or,
// // clis.AbortOn("{{.Name}}::Exec", err)
// return nil
// }
// Template for "{{.Name}}" CLI handling ends here
{{end}}
|