github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/cf/flagcontext/flag_content_helper.go (about)

     1  package flagcontext
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"strings"
     7  )
     8  
     9  func GetContentsFromFlagValue(input string) ([]byte, error) {
    10  	if len(input) == 0 {
    11  		return []byte{}, fmt.Errorf("invalid input: %s", input)
    12  	}
    13  
    14  	return GetContentsFromOptionalFlagValue(input)
    15  }
    16  
    17  func GetContentsFromOptionalFlagValue(input string) ([]byte, error) {
    18  	trimmedInput := strings.Trim(input, `"'`)
    19  	if strings.HasPrefix(trimmedInput, `@`) {
    20  		trimmedInput = strings.Trim(trimmedInput[1:], `"'`)
    21  		bs, err := ioutil.ReadFile(trimmedInput)
    22  		if err != nil {
    23  			return []byte{}, err
    24  		}
    25  
    26  		return bs, nil
    27  	}
    28  
    29  	bs, err := ioutil.ReadFile(trimmedInput)
    30  	if err != nil {
    31  		return []byte(trimmedInput), nil
    32  	}
    33  
    34  	return bs, nil
    35  }