This commit is contained in:
ideahitme 2017-03-02 16:47:38 +01:00
parent 885b2349e1
commit a0b66b91f3
3 changed files with 47 additions and 2 deletions

View File

@ -42,7 +42,6 @@ import (
func main() {
cfg := externaldns.NewConfig()
if err := cfg.ParseFlags(os.Args); err != nil {
log.Fatalf("flag parsing error: %v", err)
}

View File

@ -16,7 +16,11 @@ limitations under the License.
package externaldns
import "github.com/spf13/pflag"
import (
"fmt"
"github.com/spf13/pflag"
)
var (
defaultHealthPort = "9090"
@ -41,6 +45,7 @@ func NewConfig() *Config {
// ParseFlags adds and parses flags from command line
func (cfg *Config) ParseFlags(args []string) error {
fmt.Println(args)
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
flags.BoolVar(&cfg.InCluster, "in-cluster", false, "whether to use in-cluster config")
flags.StringVar(&cfg.KubeConfig, "kubeconfig", "", "path to a local kubeconfig file")

View File

@ -0,0 +1,41 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package externaldns
import "testing"
func TestParseFlags(t *testing.T) {
// extra := "one-extra-argument"
// args := []string{
// "-bool",
// "-bool2=true",
// "--int", "22",
// "--int64", "0x23",
// "-uint", "24",
// "--uint64", "25",
// "-string", "hello",
// "-float64", "2718e28",
// "-duration", "2m",
// extra,
// }
}
type arg struct {
raw string
key string
val string
}