github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/cmd/juju/resource/file.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package resource
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  
    10  	"github.com/juju/errors"
    11  )
    12  
    13  // resourceFile associates a resource name to a filename.
    14  type resourceFile struct {
    15  	application string
    16  	name        string
    17  	filename    string
    18  }
    19  
    20  // parseResourceFileArg converts the provided string into a name and
    21  // filename. The string must be in the "<name>=<filename>" format.
    22  func parseResourceFileArg(raw string) (name string, filename string, _ error) {
    23  	vals := strings.SplitN(raw, "=", 2)
    24  	if len(vals) < 2 {
    25  		msg := fmt.Sprintf("expected name=path format")
    26  		return "", "", errors.NewNotValid(nil, msg)
    27  	}
    28  
    29  	name, filename = vals[0], vals[1]
    30  	if name == "" {
    31  		return "", "", errors.NewNotValid(nil, "missing resource name")
    32  	}
    33  	if filename == "" {
    34  		return "", "", errors.NewNotValid(nil, "missing filename")
    35  	}
    36  	return name, filename, nil
    37  }