github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/cmd/swarmctl/service/flagparser/volume.go (about)

     1  package flagparser
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/docker/swarmkit/api"
     8  	"github.com/spf13/pflag"
     9  )
    10  
    11  // parseVolume only supports a very simple version of anonymous volumes for
    12  // testing the most basic of data flows. Replace with a --mount flag, similar
    13  // to what we have in docker service.
    14  func parseVolume(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
    15  	if flags.Changed("volume") {
    16  		volumes, err := flags.GetStringSlice("volume")
    17  		if err != nil {
    18  			return err
    19  		}
    20  
    21  		container := spec.Task.GetContainer()
    22  
    23  		for _, volume := range volumes {
    24  			if strings.Contains(volume, ":") {
    25  				return fmt.Errorf("volume format %q not supported", volume)
    26  			}
    27  			container.Mounts = append(container.Mounts, api.Mount{
    28  				Type:   api.MountTypeVolume,
    29  				Target: volume,
    30  			})
    31  		}
    32  	}
    33  
    34  	return nil
    35  }