kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/go/extractors/gcp/config/yamlgen/yamlgen.go (about)

     1  /*
     2   * Copyright 2018 The Kythe Authors. All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *   http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  // Binary yamlgen generates a Cloud Build yaml config file for extracting a
    18  // repo using Kythe.
    19  package main
    20  
    21  import (
    22  	"flag"
    23  	"io/ioutil"
    24  
    25  	"kythe.io/kythe/go/extractors/gcp/config"
    26  	"kythe.io/kythe/go/util/log"
    27  )
    28  
    29  var (
    30  	input  = flag.String("input", "", "The input config proto to read.")
    31  	output = flag.String("output", "", "The output yaml file to write.")
    32  )
    33  
    34  func main() {
    35  	flag.Parse()
    36  	checkFlags()
    37  
    38  	yamlData, err := config.KytheToYAML(*input)
    39  	if err != nil {
    40  		log.Fatalf("failure converting %s to %s: %v", *input, *output, err)
    41  	}
    42  
    43  	if err := ioutil.WriteFile(*output, yamlData, 0644); err != nil {
    44  		log.Fatalf("failure writing data to %s: %v", *output, err)
    45  	}
    46  }
    47  
    48  func checkFlags() {
    49  	failed := false
    50  	if *input == "" {
    51  		log.Info("Must specify --input on commandline")
    52  		failed = true
    53  	}
    54  	if *output == "" {
    55  		log.Info("Must specify --output on commandline")
    56  		failed = true
    57  	}
    58  	if failed {
    59  		log.Fatalln("Flags not set properly.")
    60  	}
    61  }