-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.go
More file actions
74 lines (70 loc) · 1.78 KB
/
commands.go
File metadata and controls
74 lines (70 loc) · 1.78 KB
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
package main
import (
"fmt"
"github.com/codegangsta/cli"
"log"
"os"
)
var Commands = []cli.Command{
commandGenerate,
commandTemplate,
}
var commandGenerate = cli.Command{
Name: "generate",
Usage: "Generate structure definition(s)",
UsageText: "structr generate -c YOUR_CONFIGURATION_FILE [filepath...]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Value: "",
Usage: "(REQUIRED) configuration file for structr",
},
cli.StringFlag{
Name: "type, t",
Value: "json",
Usage: "input file type",
},
cli.StringFlag{
Name: "outDir",
Value: "",
Usage: "output directory for generated structure",
},
},
Action: func(c *cli.Context) {
args := c.Args()
if len(args) < 1 {
cli.ShowAppHelp(c)
os.Exit(1)
}
bedrock, err := NewBedrock(c.String("config"), c.String("type"), c.String("outDir"), args)
if err != nil {
log.Fatalln("initialize error: ", err.Error())
}
var creator NodeCreator
switch bedrock.InputType {
case INPUT_TYPE_JSON:
bundler := NewJsonSchemaBundler(NewJsonSchemaLoader())
if err := bundler.AddJsonSchema(bedrock.Inputs...); err != nil {
log.Fatalln("cannot add load json schema: ", err.Error())
}
creator = NewJsonSchemaNodeCreator(bundler)
case INPUT_TYPE_UNKNOWN:
log.Fatalln("unknown input type")
}
if err := creator.Create(NewExporter(bedrock)); err != nil {
log.Fatalln("failed export: ", err.Error())
}
},
}
var commandTemplate = cli.Command{
Name: "template",
Usage: "Output template of configuration file",
UsageText: "structr template > YOUR_CONFIGURATION_NAME.yml",
Action: func(c *cli.Context) {
bytes, err := Asset("resources/config.yml")
if err != nil {
log.Fatalln("cannot load configuration template: ", err)
}
fmt.Print(string(bytes[:]))
},
}