add badflag test #38
							
								
								
									
										2
									
								
								flag.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								flag.go
									
									
									
									
									
								
							@@ -5,6 +5,7 @@ import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"flag"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"reflect"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
@@ -44,6 +45,7 @@ func (c *flagConfig) Init(opts ...config.Option) error {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	flag.CommandLine.Init(os.Args[0], flag.ContinueOnError)
 | 
			
		||||
	for _, sf := range fields {
 | 
			
		||||
		tf, ok := sf.Field.Tag.Lookup(c.opts.StructTag)
 | 
			
		||||
		if !ok {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								flag_test.go
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								flag_test.go
									
									
									
									
									
								
							@@ -18,21 +18,23 @@ func TestLoad(t *testing.T) {
 | 
			
		||||
	os.Args = append(os.Args, "-time", time.RFC822)
 | 
			
		||||
	os.Args = append(os.Args, "-metadata", "key=20")
 | 
			
		||||
	os.Args = append(os.Args, "-components", "all=info,api=debug")
 | 
			
		||||
	os.Args = append(os.Args, "-addr", "33,44")
 | 
			
		||||
	os.Args = append(os.Args, "-badflag", "test")
 | 
			
		||||
	type NestedConfig struct {
 | 
			
		||||
		Value string `flag:"name=nested_value"`
 | 
			
		||||
	}
 | 
			
		||||
	type Config struct {
 | 
			
		||||
		Broker         string            `flag:"name=broker,desc='description with, comma',default='127.0.0.1:9092'"`
 | 
			
		||||
		Verbose        bool              `flag:"name=verbose,desc='verbose output',default='false'"`
 | 
			
		||||
		Addr           []string          `flag:"name=addr,desc='addrs',default='127.0.0.1:9092'"`
 | 
			
		||||
		Wait           time.Duration     `flag:"name=wait,desc='wait time',default='2s'"`
 | 
			
		||||
		Time           time.Time         `flag:"name=time,desc='some time',default='02 Jan 06 15:04 MST'"`
 | 
			
		||||
		Metadata       map[string]int    `flag:"name=metadata,desc='some meta',default=''"`
 | 
			
		||||
		WithoutDefault string            `flag:"name=without_default,desc='with'"`
 | 
			
		||||
		WithoutDesc    string            `flag:"name=without_desc,default='without_default'"`
 | 
			
		||||
		WithoutAll     string            `flag:"name=without_all"`
 | 
			
		||||
		Components     map[string]string `flag:"name=components,desc='components logging'"`
 | 
			
		||||
		Metadata       map[string]int    `flag:"name=metadata,desc='some meta',default=''"`
 | 
			
		||||
		Nested         *NestedConfig
 | 
			
		||||
		Broker         string        `flag:"name=broker,desc='description with, comma',default='127.0.0.1:9092'"`
 | 
			
		||||
		WithoutDesc    string        `flag:"name=without_desc,default='without_default'"`
 | 
			
		||||
		WithoutAll     string        `flag:"name=without_all"`
 | 
			
		||||
		WithoutDefault string        `flag:"name=without_default,desc='with'"`
 | 
			
		||||
		Addr           []string      `flag:"name=addr,desc='addrs',default='127.0.0.1:9092'"`
 | 
			
		||||
		Wait           time.Duration `flag:"name=wait,desc='wait time',default='2s'"`
 | 
			
		||||
		Verbose        bool          `flag:"name=verbose,desc='verbose output',default='false'"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx := context.Background()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								util.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								util.go
									
									
									
									
									
								
							@@ -10,9 +10,9 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type mapValue struct {
 | 
			
		||||
	v     reflect.Value
 | 
			
		||||
	delim string
 | 
			
		||||
	def   string
 | 
			
		||||
	v     reflect.Value
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (v mapValue) String() string {
 | 
			
		||||
@@ -67,9 +67,9 @@ func (v mapValue) Set(s string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type sliceValue struct {
 | 
			
		||||
	v     reflect.Value
 | 
			
		||||
	delim string
 | 
			
		||||
	def   string
 | 
			
		||||
	v     reflect.Value
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (v sliceValue) String() string {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user