github.com/solo-io/cue@v0.4.7/pkg/tool/gen.go (about)

     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  
    15  //go:build ignore
    16  // +build ignore
    17  
    18  package main
    19  
    20  // TODO: remove when we have a cuedoc server. Until then,
    21  // piggyback on pkg.go.dev.
    22  
    23  import (
    24  	"bytes"
    25  	"fmt"
    26  	"io/ioutil"
    27  	"os"
    28  )
    29  
    30  const msg = `// Code generated by cue get go. DO NOT EDIT.
    31  
    32  // Package tool defines statefull operation types for cue commands.
    33  //
    34  // This package is only visible in cue files with a _tool.cue or _tool_test.cue
    35  // ending.
    36  //
    37  // CUE configuration files are not influenced by and do not influence anything
    38  // outside the configuration itself: they are hermetic. Tools solve
    39  // two problems: allow outside values such as environment variables,
    40  // file or web contents, random generators etc. to influence configuration,
    41  // and allow configuration to be actionable from within the tooling itself.
    42  // Separating these concerns makes it clear to user when outside influences are
    43  // in play and the tool definition can be strict about what is allowed.
    44  //
    45  // Tools are defined in files ending with _tool.cue. These files have a
    46  // top-level map, "command", which defines all the tools made available through
    47  // the cue command.
    48  //
    49  // The following definitions are for defining commands in tool files:
    50  //     %s
    51  package tool
    52  `
    53  
    54  func main() {
    55  	f, _ := os.Create("doc.go")
    56  	defer f.Close()
    57  	b, _ := ioutil.ReadFile("tool.cue")
    58  	i := bytes.Index(b, []byte("package tool"))
    59  	b = b[i+len("package tool")+1:]
    60  	b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n//     "))
    61  	fmt.Fprintf(f, msg, string(b))
    62  }