Add validators schema and code templates
This commit is contained in:
47
src/templates/go.handlebars
Normal file
47
src/templates/go.handlebars
Normal file
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var version = "{{spec.version}}"
|
||||
|
||||
{{#each spec.globalOptions}}
|
||||
var {{goVarName name}} {{#if (eq type "string")}}string{{else if (eq type "number")}}int{{else if (eq type "boolean")}}bool{{else}}string{{/if}}
|
||||
{{/each}}
|
||||
|
||||
func main() {
|
||||
{{#each spec.globalOptions}}
|
||||
flag.{{#if (eq type "string")}}StringVar{{else if (eq type "number")}}IntVar{{else if (eq type "boolean")}}BoolVar{{else}}StringVar{{/if}}(&{{goVarName name}}, "{{name}}", {{#if default}}{{toJson default}}{{else}}nil{{/if}}, "{{escape description}}")
|
||||
{{/each}}
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "{{spec.name}} - {{spec.description}}\\n\\nUsage:\\n %s [options] <command> [args]\\n\\nOptions:\\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
fmt.Fprintf(os.Stderr, "\\nCommands:\\n")
|
||||
{{#each spec.commands}}
|
||||
fmt.Fprintf(os.Stderr, " %-15s %s\\n", "{{name}}", "{{escape description}}")
|
||||
{{/each}}
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) < 1 {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
switch args[0] {
|
||||
{{#each spec.commands}}
|
||||
case "{{name}}":
|
||||
fmt.Println("Command: {{name}}")
|
||||
{{/each}}
|
||||
default:
|
||||
fmt.Printf("Unknown command: %s\\n", args[0])
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user