github.com/status-im/status-go@v1.1.0/cmd/spiff-workflow/flags.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path"
     7  	"strings"
     8  )
     9  
    10  // configFlags represents an array of JSON configuration files passed to a command line utility
    11  type configFlags []string
    12  
    13  func (f *configFlags) String() string {
    14  	return strings.Join(*f, ", ")
    15  }
    16  
    17  func (f *configFlags) Set(value string) error {
    18  	if !path.IsAbs(value) {
    19  		// Convert to absolute path
    20  		cwd, err := os.Getwd()
    21  		if err != nil {
    22  			return err
    23  		}
    24  		value = path.Join(cwd, value)
    25  	}
    26  
    27  	// Check that the file exists
    28  	stat, err := os.Stat(value)
    29  	if err != nil {
    30  		return err
    31  	}
    32  	if stat.IsDir() {
    33  		return fmt.Errorf("path does not represent a file: %s", value)
    34  	}
    35  	*f = append(*f, value)
    36  	return nil
    37  }