示例#1
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseGenericFromEnvCascade(t *testing.T) {
	os.Clearenv()
	os.Setenv("APP_FOO", "99,2000")
	a := cli.App{
		Flags: []cli.Flag{
			cli.GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
		},
		Action: func(ctx *cli.Context) int {
			if !reflect.DeepEqual(ctx.Generic("foos"), &Parser{"99", "2000"}) {
				t.Errorf("value not set from env")
			}
			return 0
		},
	}
	a.Run([]string{"run"})
}
示例#2
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseGeneric(t *testing.T) {
	a := cli.App{
		Flags: []cli.Flag{
			cli.GenericFlag{Name: "serve, s", Value: &Parser{}},
		},
		Action: func(ctx *cli.Context) int {
			if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"10", "20"}) {
				t.Errorf("main name not set")
			}
			if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"10", "20"}) {
				t.Errorf("short name not set")
			}
			return 0
		},
	}
	a.Run([]string{"run", "-s", "10,20"})
}
示例#3
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseMultiBoolT(t *testing.T) {
	a := cli.App{
		Flags: []cli.Flag{
			cli.BoolTFlag{Name: "serve, s"},
		},
		Action: func(ctx *cli.Context) int {
			if ctx.BoolT("serve") != true {
				t.Errorf("main name not set")
			}
			if ctx.BoolT("s") != true {
				t.Errorf("short name not set")
			}
			return 0
		},
	}
	a.Run([]string{"run", "--serve"})
}
示例#4
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseMultiFloat64(t *testing.T) {
	a := cli.App{
		Flags: []cli.Flag{
			cli.Float64Flag{Name: "serve, s"},
		},
		Action: func(ctx *cli.Context) int {
			if ctx.Float64("serve") != 10.2 {
				t.Errorf("main name not set")
			}
			if ctx.Float64("s") != 10.2 {
				t.Errorf("short name not set")
			}
			return 0
		},
	}
	a.Run([]string{"run", "-s", "10.2"})
}
示例#5
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseGenericFromEnv(t *testing.T) {
	os.Clearenv()
	os.Setenv("APP_SERVE", "20,30")
	a := cli.App{
		Flags: []cli.Flag{
			cli.GenericFlag{Name: "serve, s", Value: &Parser{}, EnvVar: "APP_SERVE"},
		},
		Action: func(ctx *cli.Context) int {
			if !reflect.DeepEqual(ctx.Generic("serve"), &Parser{"20", "30"}) {
				t.Errorf("main name not set from env")
			}
			if !reflect.DeepEqual(ctx.Generic("s"), &Parser{"20", "30"}) {
				t.Errorf("short name not set from env")
			}
			return 0
		},
	}
	a.Run([]string{"run"})
}
示例#6
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
	os.Clearenv()
	os.Setenv("APP_DEBUG", "0")
	a := cli.App{
		Flags: []cli.Flag{
			cli.BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
		},
		Action: func(ctx *cli.Context) int {
			if ctx.BoolT("debug") != false {
				t.Errorf("main name not set from env")
			}
			if ctx.BoolT("d") != false {
				t.Errorf("short name not set from env")
			}
			return 0
		},
	}
	a.Run([]string{"run"})
}
示例#7
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
	os.Clearenv()
	os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
	a := cli.App{
		Flags: []cli.Flag{
			cli.Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
		},
		Action: func(ctx *cli.Context) int {
			if ctx.Float64("timeout") != 15.5 {
				t.Errorf("main name not set")
			}
			if ctx.Float64("t") != 15.5 {
				t.Errorf("short name not set")
			}
			return 0
		},
	}
	a.Run([]string{"run"})
}
示例#8
0
文件: flag_test.go 项目: pgpst/pgpst
func TestParseMultiIntFromEnv(t *testing.T) {
	os.Clearenv()
	os.Setenv("APP_TIMEOUT_SECONDS", "10")
	a := cli.App{
		Flags: []cli.Flag{
			cli.IntFlag{Name: "timeout, t", EnvVar: "APP_TIMEOUT_SECONDS"},
		},
		Action: func(ctx *cli.Context) int {
			if ctx.Int("timeout") != 10 {
				t.Errorf("main name not set")
			}
			if ctx.Int("t") != 10 {
				t.Errorf("short name not set")
			}
			return 0
		},
	}
	a.Run([]string{"run"})
}