(dockerCLI command.Cli)
| 22 | var errNoRoleChange = errors.New("role was already set to the requested value") |
| 23 | |
| 24 | func newUpdateCommand(dockerCLI command.Cli) *cobra.Command { |
| 25 | options := newNodeOptions() |
| 26 | |
| 27 | cmd := &cobra.Command{ |
| 28 | Use: "update [OPTIONS] NODE", |
| 29 | Short: "Update a node", |
| 30 | Args: cli.ExactArgs(1), |
| 31 | RunE: func(cmd *cobra.Command, args []string) error { |
| 32 | return runUpdate(cmd.Context(), dockerCLI, cmd.Flags(), args[0]) |
| 33 | }, |
| 34 | ValidArgsFunction: completeNodeNames(dockerCLI), |
| 35 | DisableFlagsInUseLine: true, |
| 36 | } |
| 37 | |
| 38 | flags := cmd.Flags() |
| 39 | flags.StringVar(&options.role, flagRole, "", `Role of the node ("worker", "manager")`) |
| 40 | flags.StringVar(&options.availability, flagAvailability, "", `Availability of the node ("active", "pause", "drain")`) |
| 41 | flags.Var(&options.annotations.labels, flagLabelAdd, `Add or update a node label ("key=value")`) |
| 42 | labelKeys := opts.NewListOpts(nil) |
| 43 | flags.Var(&labelKeys, flagLabelRemove, "Remove a node label if exists") |
| 44 | |
| 45 | _ = cmd.RegisterFlagCompletionFunc(flagRole, completion.FromList("worker", "manager")) |
| 46 | _ = cmd.RegisterFlagCompletionFunc(flagAvailability, completion.FromList("active", "pause", "drain")) |
| 47 | |
| 48 | return cmd |
| 49 | } |
| 50 | |
| 51 | func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, nodeID string) error { |
| 52 | return updateNodes(ctx, dockerCLI.Client(), []string{nodeID}, mergeNodeUpdate(flags), func(_ string) { |
searching dependent graphs…