2018-07-04 10:51:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-09-13 16:31:29 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path"
|
2018-07-04 10:51:47 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
// configFlags represents an array of JSON configuration files passed to a command line utility
|
|
|
|
type configFlags []string
|
2018-07-04 10:51:47 +00:00
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
func (f *configFlags) String() string {
|
|
|
|
return strings.Join(*f, ", ")
|
2018-07-04 10:51:47 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 16:31:29 +00:00
|
|
|
func (f *configFlags) Set(value string) error {
|
|
|
|
if !path.IsAbs(value) {
|
|
|
|
// Convert to absolute path
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
value = path.Join(cwd, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the file exists
|
|
|
|
stat, err := os.Stat(value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if stat.IsDir() {
|
|
|
|
return fmt.Errorf("path does not represent a file: %s", value)
|
2018-07-04 10:51:47 +00:00
|
|
|
}
|
2018-09-13 16:31:29 +00:00
|
|
|
*f = append(*f, value)
|
2018-07-04 10:51:47 +00:00
|
|
|
return nil
|
|
|
|
}
|