本文整理匯總了Golang中github.com/spf13/pflag.FlagSet.GetUint64方法的典型用法代碼示例。如果您正苦於以下問題:Golang FlagSet.GetUint64方法的具體用法?Golang FlagSet.GetUint64怎麽用?Golang FlagSet.GetUint64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/spf13/pflag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.GetUint64方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: parseUpdate
func parseUpdate(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("update-parallelism") {
parallelism, err := flags.GetUint64("update-parallelism")
if err != nil {
return err
}
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
spec.Update.Parallelism = parallelism
}
if flags.Changed("update-delay") {
delay, err := flags.GetString("update-delay")
if err != nil {
return err
}
delayDuration, err := time.ParseDuration(delay)
if err != nil {
return err
}
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
spec.Update.Delay = *ptypes.DurationProto(delayDuration)
}
return nil
}
示例2: parseUpdate
func parseUpdate(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("update-parallelism") {
parallelism, err := flags.GetUint64("update-parallelism")
if err != nil {
return err
}
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
spec.Update.Parallelism = parallelism
}
if flags.Changed("update-delay") {
delay, err := flags.GetString("update-delay")
if err != nil {
return err
}
delayDuration, err := time.ParseDuration(delay)
if err != nil {
return err
}
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
spec.Update.Delay = delayDuration
}
if flags.Changed("update-on-failure") {
if spec.Update == nil {
spec.Update = &api.UpdateConfig{}
}
action, err := flags.GetString("update-on-failure")
if err != nil {
return err
}
switch action {
case "pause":
spec.Update.FailureAction = api.UpdateConfig_PAUSE
case "continue":
spec.Update.FailureAction = api.UpdateConfig_CONTINUE
default:
return errors.New("--update-on-failure value must be pause or continue")
}
}
return nil
}
示例3: parseMode
func parseMode(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("mode") {
mode, err := flags.GetString("mode")
if err != nil {
return err
}
switch mode {
case "global":
if spec.GetGlobal() == nil {
spec.Mode = &api.ServiceSpec_Global{
Global: &api.GlobalService{},
}
}
case "replicated":
if spec.GetReplicated() == nil {
spec.Mode = &api.ServiceSpec_Replicated{
Replicated: &api.ReplicatedService{},
}
}
}
}
if flags.Changed("replicas") {
if spec.GetReplicated() == nil {
return fmt.Errorf("--replicas can only be specified in --mode replicated")
}
replicas, err := flags.GetUint64("replicas")
if err != nil {
return err
}
spec.GetReplicated().Replicas = replicas
}
return nil
}
示例4: mergeService
func mergeService(spec *swarm.ServiceSpec, flags *pflag.FlagSet) error {
mergeString := func(flag string, field *string) {
if flags.Changed(flag) {
*field, _ = flags.GetString(flag)
}
}
mergeListOpts := func(flag string, field *[]string) {
if flags.Changed(flag) {
value := flags.Lookup(flag).Value.(*opts.ListOpts)
*field = value.GetAll()
}
}
mergeSlice := func(flag string, field *[]string) {
if flags.Changed(flag) {
*field, _ = flags.GetStringSlice(flag)
}
}
mergeInt64Value := func(flag string, field *int64) {
if flags.Changed(flag) {
*field = flags.Lookup(flag).Value.(int64Value).Value()
}
}
mergeDuration := func(flag string, field *time.Duration) {
if flags.Changed(flag) {
*field, _ = flags.GetDuration(flag)
}
}
mergeDurationOpt := func(flag string, field *time.Duration) {
if flags.Changed(flag) {
*field = *flags.Lookup(flag).Value.(*DurationOpt).Value()
}
}
mergeUint64 := func(flag string, field *uint64) {
if flags.Changed(flag) {
*field, _ = flags.GetUint64(flag)
}
}
mergeUint64Opt := func(flag string, field *uint64) {
if flags.Changed(flag) {
*field = *flags.Lookup(flag).Value.(*Uint64Opt).Value()
}
}
cspec := &spec.TaskTemplate.ContainerSpec
task := &spec.TaskTemplate
mergeString("name", &spec.Name)
mergeLabels(flags, &spec.Labels)
mergeString("image", &cspec.Image)
mergeSlice("command", &cspec.Command)
mergeSlice("arg", &cspec.Command)
mergeListOpts("env", &cspec.Env)
mergeString("workdir", &cspec.Dir)
mergeString("user", &cspec.User)
mergeMounts(flags, &cspec.Mounts)
mergeInt64Value("limit-cpu", &task.Resources.Limits.NanoCPUs)
mergeInt64Value("limit-memory", &task.Resources.Limits.MemoryBytes)
mergeInt64Value("reserve-cpu", &task.Resources.Reservations.NanoCPUs)
mergeInt64Value("reserve-memory", &task.Resources.Reservations.MemoryBytes)
mergeDurationOpt("stop-grace-period", cspec.StopGracePeriod)
if flags.Changed("restart-policy-condition") {
value, _ := flags.GetString("restart-policy-condition")
task.RestartPolicy.Condition = swarm.RestartPolicyCondition(value)
}
mergeDurationOpt("restart-policy-delay", task.RestartPolicy.Delay)
mergeUint64Opt("restart-policy-max-attempts", task.RestartPolicy.MaxAttempts)
mergeDurationOpt("restart-policy-window", task.RestartPolicy.Window)
mergeSlice("constraint", &task.Placement.Constraints)
if err := mergeMode(flags, &spec.Mode); err != nil {
return err
}
mergeUint64("updateconfig-parallelism", &spec.UpdateConfig.Parallelism)
mergeDuration("updateconfig-delay", &spec.UpdateConfig.Delay)
mergeNetworks(flags, &spec.Networks)
if flags.Changed("endpoint-mode") {
value, _ := flags.GetString("endpoint-mode")
spec.EndpointSpec.Mode = swarm.ResolutionMode(value)
}
mergePorts(flags, &spec.EndpointSpec.Ports)
return nil
}
示例5: mergeService
func mergeService(spec *swarm.ServiceSpec, flags *pflag.FlagSet) error {
mergeString := func(flag string, field *string) {
if flags.Changed(flag) {
*field, _ = flags.GetString(flag)
}
}
mergeListOpts := func(flag string, field *[]string) {
if flags.Changed(flag) {
value := flags.Lookup(flag).Value.(*opts.ListOpts)
*field = value.GetAll()
}
}
mergeSlice := func(flag string, field *[]string) {
if flags.Changed(flag) {
*field, _ = flags.GetStringSlice(flag)
}
}
mergeInt64Value := func(flag string, field *int64) {
if flags.Changed(flag) {
*field = flags.Lookup(flag).Value.(int64Value).Value()
}
}
mergeDuration := func(flag string, field *time.Duration) {
if flags.Changed(flag) {
*field, _ = flags.GetDuration(flag)
}
}
mergeDurationOpt := func(flag string, field *time.Duration) {
if flags.Changed(flag) {
*field = *flags.Lookup(flag).Value.(*DurationOpt).Value()
}
}
mergeUint64 := func(flag string, field *uint64) {
if flags.Changed(flag) {
*field, _ = flags.GetUint64(flag)
}
}
mergeUint64Opt := func(flag string, field *uint64) {
if flags.Changed(flag) {
*field = *flags.Lookup(flag).Value.(*Uint64Opt).Value()
}
}
cspec := &spec.TaskTemplate.ContainerSpec
task := &spec.TaskTemplate
mergeString(flagName, &spec.Name)
mergeLabels(flags, &spec.Labels)
mergeString("image", &cspec.Image)
mergeSlice("command", &cspec.Command)
mergeSlice("arg", &cspec.Command)
mergeListOpts("env", &cspec.Env)
mergeString("workdir", &cspec.Dir)
mergeString("user", &cspec.User)
mergeMounts(flags, &cspec.Mounts)
if flags.Changed(flagLimitCPU) || flags.Changed(flagLimitMemory) {
if task.Resources == nil {
task.Resources = &swarm.ResourceRequirements{}
}
task.Resources.Limits = &swarm.Resources{}
mergeInt64Value(flagLimitCPU, &task.Resources.Limits.NanoCPUs)
mergeInt64Value(flagLimitMemory, &task.Resources.Limits.MemoryBytes)
}
if flags.Changed(flagReserveCPU) || flags.Changed(flagReserveMemory) {
if task.Resources == nil {
task.Resources = &swarm.ResourceRequirements{}
}
task.Resources.Reservations = &swarm.Resources{}
mergeInt64Value(flagReserveCPU, &task.Resources.Reservations.NanoCPUs)
mergeInt64Value(flagReserveMemory, &task.Resources.Reservations.MemoryBytes)
}
mergeDurationOpt("stop-grace-period", cspec.StopGracePeriod)
if flags.Changed(flagRestartCondition) || flags.Changed(flagRestartDelay) || flags.Changed(flagRestartMaxAttempts) || flags.Changed(flagRestartWindow) {
if task.RestartPolicy == nil {
task.RestartPolicy = &swarm.RestartPolicy{}
}
if flags.Changed(flagRestartCondition) {
value, _ := flags.GetString(flagRestartCondition)
task.RestartPolicy.Condition = swarm.RestartPolicyCondition(value)
}
mergeDurationOpt(flagRestartDelay, task.RestartPolicy.Delay)
mergeUint64Opt(flagRestartMaxAttempts, task.RestartPolicy.MaxAttempts)
mergeDurationOpt((flagRestartWindow), task.RestartPolicy.Window)
}
if flags.Changed(flagConstraint) {
task.Placement = &swarm.Placement{}
mergeSlice(flagConstraint, &task.Placement.Constraints)
//.........這裏部分代碼省略.........
示例6: parseRestart
func parseRestart(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("restart-condition") {
condition, err := flags.GetString("restart-condition")
if err != nil {
return err
}
if spec.Task.Restart == nil {
spec.Task.Restart = &api.RestartPolicy{}
}
switch condition {
case "none":
spec.Task.Restart.Condition = api.RestartOnNone
case "failure":
spec.Task.Restart.Condition = api.RestartOnFailure
case "any":
spec.Task.Restart.Condition = api.RestartOnAny
default:
return fmt.Errorf("invalid restart condition: %s", condition)
}
}
if flags.Changed("restart-delay") {
delay, err := flags.GetString("restart-delay")
if err != nil {
return err
}
delayDuration, err := time.ParseDuration(delay)
if err != nil {
return err
}
if spec.Task.Restart == nil {
spec.Task.Restart = &api.RestartPolicy{}
}
spec.Task.Restart.Delay = ptypes.DurationProto(delayDuration)
}
if flags.Changed("restart-max-attempts") {
attempts, err := flags.GetUint64("restart-max-attempts")
if err != nil {
return err
}
if spec.Task.Restart == nil {
spec.Task.Restart = &api.RestartPolicy{}
}
spec.Task.Restart.MaxAttempts = attempts
}
if flags.Changed("restart-window") {
window, err := flags.GetString("restart-window")
if err != nil {
return err
}
windowDelay, err := time.ParseDuration(window)
if err != nil {
return err
}
if spec.Task.Restart == nil {
spec.Task.Restart = &api.RestartPolicy{}
}
spec.Task.Restart.Window = ptypes.DurationProto(windowDelay)
}
return nil
}