github.com/dnephin/dobi@v0.15.0/tasks/mount/paths.go (about)

     1  package mount
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"github.com/dnephin/dobi/config"
     8  )
     9  
    10  // AsBind returns a MountConfig formatted as a bind mount string
    11  func AsBind(c *config.MountConfig, workingDir string) string {
    12  	var mode string
    13  	if c.ReadOnly {
    14  		mode = "ro"
    15  	} else {
    16  		mode = "rw"
    17  	}
    18  	return fmt.Sprintf("%s:%s:%s", AbsBindPath(c, workingDir), c.Path, mode)
    19  }
    20  
    21  // AbsBindPath returns the MountConfig.Bind as an absolute path
    22  func AbsBindPath(c *config.MountConfig, workingDir string) string {
    23  	switch {
    24  	case c.Name != "":
    25  		return c.Name
    26  	case filepath.IsAbs(c.Bind):
    27  		return c.Bind
    28  	default:
    29  		return filepath.Join(workingDir, c.Bind)
    30  	}
    31  }