本文整理汇总了Golang中flag.NewFlagSet函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFlagSet函数的具体用法?Golang NewFlagSet怎么用?Golang NewFlagSet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFlagSet函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
invalidateflags := flag.NewFlagSet("invalidate", flag.ExitOnError)
sync := invalidateflags.Bool("sync", true, "Make request synchronously")
verbose := invalidateflags.Bool("verbose", false, "Verbose output")
runflags := flag.NewFlagSet("run", flag.ExitOnError)
bail := runflags.Bool("bail", false, "Bail after a single test failure")
runverbose := runflags.Bool("verbose", false, "Verbose response output")
grepHelp := "Grep for the given pattern"
grep := runflags.String("grep", "", grepHelp)
runflags.StringVar(grep, "g", "", grepHelp+" (shorthand)")
if len(os.Args) < 2 {
usage()
}
switch os.Args[1] {
case "invalidate":
err := invalidateflags.Parse(os.Args[2:])
if err != nil {
handleError(err, true)
}
doInvalidate(invalidateflags, *sync, *verbose)
case "run":
err := runflags.Parse(os.Args[2:])
if err != nil {
handleError(err, true)
}
doRun(runflags, *bail, *runverbose, *grep)
default:
usage()
}
}
开发者ID:Shyp,项目名称:lucifer,代码行数:30,代码来源:main.go
示例2: TestCliFlagsToCfnStackParams
func TestCliFlagsToCfnStackParams(t *testing.T) {
globalSet := flag.NewFlagSet("ecs-cli", 0)
globalSet.String("region", "us-west-1", "")
globalContext := cli.NewContext(nil, globalSet, nil)
flagSet := flag.NewFlagSet("ecs-cli-up", 0)
flagSet.Bool(capabilityIAMFlag, true, "")
flagSet.String(keypairNameFlag, "default", "")
context := cli.NewContext(nil, flagSet, globalContext)
params := cliFlagsToCfnStackParams(context)
_, err := params.GetParameter(cloudformation.ParameterKeyAsgMaxSize)
if err == nil {
t.Fatalf("Expected error for parameter '%s'", cloudformation.ParameterKeyAsgMaxSize)
}
if cloudformation.ParameterNotFoundError != err {
t.Error("Enexpected error returned: ", err)
}
flagSet.String(asgMaxSizeFlag, "2", "")
context = cli.NewContext(nil, flagSet, globalContext)
params = cliFlagsToCfnStackParams(context)
_, err = params.GetParameter(cloudformation.ParameterKeyAsgMaxSize)
if err != nil {
t.Error("Error getting parameter '%s'", cloudformation.ParameterKeyAsgMaxSize)
}
}
开发者ID:jloper3,项目名称:amazon-ecs-cli,代码行数:28,代码来源:cluster_app_test.go
示例3: TestNewContext
func TestNewContext(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int("myflag", 12, "doc")
set.Int64("myflagInt64", int64(12), "doc")
set.Uint("myflagUint", uint(93), "doc")
set.Uint64("myflagUint64", uint64(93), "doc")
set.Float64("myflag64", float64(17), "doc")
globalSet := flag.NewFlagSet("test", 0)
globalSet.Int("myflag", 42, "doc")
globalSet.Int64("myflagInt64", int64(42), "doc")
globalSet.Uint("myflagUint", uint(33), "doc")
globalSet.Uint64("myflagUint64", uint64(33), "doc")
globalSet.Float64("myflag64", float64(47), "doc")
globalCtx := NewContext(nil, globalSet, nil)
command := Command{Name: "mycommand"}
c := NewContext(nil, set, globalCtx)
c.Command = command
expect(t, c.Int("myflag"), 12)
expect(t, c.Int64("myflagInt64"), int64(12))
expect(t, c.Uint("myflagUint"), uint(93))
expect(t, c.Uint64("myflagUint64"), uint64(93))
expect(t, c.Float64("myflag64"), float64(17))
expect(t, c.GlobalInt("myflag"), 42)
expect(t, c.GlobalInt64("myflagInt64"), int64(42))
expect(t, c.GlobalUint("myflagUint"), uint(33))
expect(t, c.GlobalUint64("myflagUint64"), uint64(33))
expect(t, c.GlobalFloat64("myflag64"), float64(47))
expect(t, c.Command.Name, "mycommand")
}
开发者ID:realestate-com-au,项目名称:shush,代码行数:29,代码来源:context_test.go
示例4: commandWorker
func commandWorker(wi *Instance, wr *wrangler.Wrangler, args []string, cell string, runFromCli bool) (Worker, error) {
action := args[0]
actionLowerCase := strings.ToLower(action)
for _, group := range commands {
for _, cmd := range group.Commands {
if strings.ToLower(cmd.Name) == actionLowerCase {
var subFlags *flag.FlagSet
if runFromCli {
subFlags = flag.NewFlagSet(action, flag.ExitOnError)
} else {
subFlags = flag.NewFlagSet(action, flag.ContinueOnError)
}
// The command may be run from an RPC and may not log to the console.
// The Wrangler logger defines where the output has to go.
subFlags.SetOutput(logutil.NewLoggerWriter(wr.Logger()))
subFlags.Usage = func() {
wr.Logger().Printf("Usage: %s %s %s\n\n", os.Args[0], cmd.Name, cmd.Params)
wr.Logger().Printf("%s\n\n", cmd.Help)
subFlags.PrintDefaults()
}
return cmd.Method(wi, wr, subFlags, args[1:])
}
}
}
if runFromCli {
flag.Usage()
} else {
PrintAllCommands(wr.Logger())
}
return nil, fmt.Errorf("unknown command: %v", action)
}
开发者ID:jmptrader,项目名称:vitess,代码行数:32,代码来源:command.go
示例5: TestClusterUp
func TestClusterUp(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEcs := mock_ecs.NewMockECSClient(ctrl)
mockCloudformation := mock_cloudformation.NewMockCloudformationClient(ctrl)
mockEcs.EXPECT().Initialize(gomock.Any())
mockEcs.EXPECT().CreateCluster(gomock.Any()).Do(func(in interface{}) {
if in.(string) != clusterName {
t.Fatal("Expected to be called with " + clusterName + " not " + in.(string))
}
}).Return(clusterName, nil)
mockCloudformation.EXPECT().Initialize(gomock.Any())
mockCloudformation.EXPECT().ValidateStackExists(gomock.Any()).Return(errors.New("error"))
mockCloudformation.EXPECT().CreateStack(gomock.Any(), gomock.Any(), gomock.Any()).Return("", nil)
mockCloudformation.EXPECT().WaitUntilCreateComplete(gomock.Any()).Return(nil)
globalSet := flag.NewFlagSet("ecs-cli", 0)
globalSet.String("region", "us-west-1", "")
globalContext := cli.NewContext(nil, globalSet, nil)
flagSet := flag.NewFlagSet("ecs-cli-up", 0)
flagSet.Bool(capabilityIAMFlag, true, "")
flagSet.String(keypairNameFlag, "default", "")
context := cli.NewContext(nil, flagSet, globalContext)
err := createCluster(context, &mockReadWriter{}, mockEcs, mockCloudformation, ami.NewStaticAmiIds())
if err != nil {
t.Fatal("Error bringing up cluster: ", err)
}
}
开发者ID:jloper3,项目名称:amazon-ecs-cli,代码行数:32,代码来源:cluster_app_test.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng