1// Copyright 2019 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
15package protobuf_test
16
17import (
18 "fmt"
19 "log"
20 "os"
21 "path/filepath"
22
23 "cuelang.org/go/cue/format"
24 "cuelang.org/go/encoding/protobuf"
25)
26
27func ExampleExtract() {
28 cwd, _ := os.Getwd()
29 var paths = []string{}
30 paths = append(paths, cwd)
31 paths = append(paths, filepath.Join(cwd, "testdata"))
32
33 f, err := protobuf.Extract("examples/basic/basic.proto", nil, &protobuf.Config{
34 Paths: paths,
35 })
36
37 if err != nil {
38 log.Fatal(err, "")
39 }
40
41 b, _ := format.Node(f)
42 fmt.Println(string(b))
43
44 // Output:
45 // // Package basic is just that: basic.
46 // package basic
47 //
48 // // This is my type.
49 // #MyType: {
50 // stringValue?: string @protobuf(1,string,name=string_value) // just any 'ole string
51 //
52 // // A method must start with a capital letter.
53 // method?: [...string] @protobuf(2,string)
54 // method?: [...=~"^[A-Z]"]
55 // exampleMap?: {
56 // [string]: string
57 // } @protobuf(3,map[string]string,example_map)
58 // }
59}