Marcel van Lohuizen | 429bd0f | 2020-02-12 19:33:05 +0100 | [diff] [blame] | 1 | // 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 | |
| 17 | package main |
| 18 | |
| 19 | import ( |
| 20 | "io/ioutil" |
| 21 | "log" |
| 22 | "os" |
| 23 | |
Marcel van Lohuizen | 845df05 | 2020-07-26 13:15:45 +0200 | [diff] [blame] | 24 | "cuelang.org/go/cue" |
Marcel van Lohuizen | 429bd0f | 2020-02-12 19:33:05 +0100 | [diff] [blame] | 25 | "cuelang.org/go/cue/load" |
| 26 | "cuelang.org/go/encoding/gocode" |
Marcel van Lohuizen | 429bd0f | 2020-02-12 19:33:05 +0100 | [diff] [blame] | 27 | ) |
| 28 | |
| 29 | func 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 | } |