github.com/abayer/test-infra@v0.0.5/prow/initupload/options.go (about) 1 /* 2 Copyright 2018 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 initupload 18 19 import ( 20 "encoding/json" 21 "flag" 22 23 "k8s.io/test-infra/prow/gcsupload" 24 ) 25 26 const ( 27 // JSONConfigEnvVar is the environment variable that 28 // utilities expect to find a full JSON configuration 29 // in when run. 30 JSONConfigEnvVar = "INITUPLOAD_OPTIONS" 31 ) 32 33 // NewOptions returns an empty Options with no nil fields 34 func NewOptions() *Options { 35 return &Options{ 36 Options: gcsupload.NewOptions(), 37 } 38 } 39 40 type Options struct { 41 *gcsupload.Options 42 43 // Log is the log file to which clone records are written. 44 // If unspecified, no clone records are uploaded. 45 Log string `json:"log,omitempty"` 46 } 47 48 // ConfigVar exposes the environment variable used 49 // to store serialized configuration 50 func (o *Options) ConfigVar() string { 51 return JSONConfigEnvVar 52 } 53 54 // LoadConfig loads options from serialized config 55 func (o *Options) LoadConfig(config string) error { 56 return json.Unmarshal([]byte(config), o) 57 } 58 59 // BindOptions binds flags to options 60 func (o *Options) BindOptions(flags *flag.FlagSet) { 61 flags.StringVar(&o.Log, "clone-log", "", "Path to the clone records log") 62 gcsupload.BindOptions(o.Options, flags) 63 } 64 65 // Complete internalizes command line arguments 66 func (o *Options) Complete(args []string) { 67 o.Options.Complete(args) 68 } 69 70 // Encode will encode the set of options in the format 71 // that is expected for the configuration environment variable 72 func Encode(options Options) (string, error) { 73 encoded, err := json.Marshal(options) 74 return string(encoded), err 75 }