github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/prow/cmd/config/main.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     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  // Package main knows how to validate config files.
    18  package main
    19  
    20  import (
    21  	"flag"
    22  	"fmt"
    23  	"os"
    24  
    25  	"k8s.io/test-infra/prow/config"
    26  	_ "k8s.io/test-infra/prow/hook"
    27  	"k8s.io/test-infra/prow/plugins"
    28  )
    29  
    30  type options struct {
    31  	configPath    string
    32  	jobConfigPath string
    33  	pluginConfig  string
    34  }
    35  
    36  func gatherOptions() options {
    37  	o := options{}
    38  	flag.StringVar(&o.configPath, "config-path", "", "Path to config file.")
    39  	flag.StringVar(&o.jobConfigPath, "job-config-path", "", "Path to prow job configs.")
    40  	flag.StringVar(&o.pluginConfig, "plugin-config", "", "Path to plugin config file.")
    41  	flag.Parse()
    42  	return o
    43  }
    44  
    45  func main() {
    46  	o := gatherOptions()
    47  	var foundError bool
    48  	if o.pluginConfig != "" {
    49  		pa := &plugins.PluginAgent{}
    50  		if err := pa.Load(o.pluginConfig); err != nil {
    51  			fmt.Fprintf(os.Stderr, "Error reading %s: %v.", o.pluginConfig, err)
    52  			foundError = true
    53  		}
    54  	}
    55  	if o.configPath != "" {
    56  		if _, err := config.Load(o.configPath, o.jobConfigPath); err != nil {
    57  			fmt.Fprintf(os.Stderr, "Error reading %s: %v.", o.configPath, err)
    58  			foundError = true
    59  		}
    60  	}
    61  	if foundError {
    62  		os.Exit(1)
    63  	}
    64  }