github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/fla9/util.go (about)

     1  package fla9
     2  
     3  import (
     4  	"io/ioutil"
     5  	"log"
     6  	"strings"
     7  )
     8  
     9  // ParseFileArg parse an argument which represents a string content,
    10  // or @file to represents the file's content.
    11  func ParseFileArg(arg string) (file string, data []byte) {
    12  	if strings.HasPrefix(arg, "@") {
    13  		f := (arg)[1:]
    14  		if v, err := ioutil.ReadFile(f); err != nil {
    15  			log.Fatalf("failed to read file %s, error: %v", f, err)
    16  			return f, nil
    17  		} else {
    18  			return f, v
    19  		}
    20  	}
    21  
    22  	return "", []byte(arg)
    23  }