blob: f0b9f03f0dffc373808c8acffe6e288d8cabcec1 [file] [log] [blame]
Marcel van Lohuizen429bd0f2020-02-12 19:33:05 +01001// Copyright 2020 CUE Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// +build ignore
16
17package main
18
19import (
20 "io/ioutil"
21 "log"
22 "os"
23
Marcel van Lohuizen845df052020-07-26 13:15:45 +020024 "cuelang.org/go/cue"
Marcel van Lohuizen429bd0f2020-02-12 19:33:05 +010025 "cuelang.org/go/cue/load"
26 "cuelang.org/go/encoding/gocode"
Marcel van Lohuizen429bd0f2020-02-12 19:33:05 +010027)
28
29func main() {
30 cwd, err := os.Getwd()
31 if err != nil {
32 log.Fatal(err)
33 }
34
35 inst := cue.Build(load.Instances([]string{"types.cue"}, &load.Config{
36 Dir: cwd,
37 ModuleRoot: cwd,
38 Module: "cuelang.org/go/cue/build",
39 }))[0]
40 if inst.Err != nil {
41 log.Fatal(inst.Err)
42 }
43
44 b, err := gocode.Generate(".", inst, &gocode.Config{})
45 if err != nil {
46 log.Fatal(err)
47 }
48
49 if err := ioutil.WriteFile("types.go", b, 0644); err != nil {
50 log.Fatal(err)
51 }
52}