From a0b66b91f33b6b836ec84fdd5d42afdb2fd05a4d Mon Sep 17 00:00:00 2001 From: ideahitme Date: Thu, 2 Mar 2017 16:47:38 +0100 Subject: [PATCH] refactor --- main.go | 1 - pkg/apis/externaldns/types.go | 7 ++++- pkg/apis/externaldns/types_test.go | 41 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 pkg/apis/externaldns/types_test.go diff --git a/main.go b/main.go index 50a86eb18..efcb0479b 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/pkg/apis/externaldns/types.go b/pkg/apis/externaldns/types.go index f4bf7fda3..757e5d1c1 100644 --- a/pkg/apis/externaldns/types.go +++ b/pkg/apis/externaldns/types.go @@ -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") diff --git a/pkg/apis/externaldns/types_test.go b/pkg/apis/externaldns/types_test.go new file mode 100644 index 000000000..78333c26b --- /dev/null +++ b/pkg/apis/externaldns/types_test.go @@ -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 +}