2017-10-08 21:09:45 +00:00
|
|
|
package main
|
2016-08-31 12:08:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2017-10-08 21:09:45 +00:00
|
|
|
"gopkg.in/urfave/cli.v2"
|
2017-06-19 09:29:30 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-09-03 18:00:40 +00:00
|
|
|
"strings"
|
2016-08-31 12:08:15 +00:00
|
|
|
)
|
|
|
|
|
2017-09-17 21:37:39 +00:00
|
|
|
// getEnvPath returns the first path found in env or empty string
|
|
|
|
func getEnvPath(env string) string {
|
|
|
|
path := filepath.SplitList(os.Getenv(env))
|
|
|
|
if len(path) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return path[0]
|
|
|
|
}
|
|
|
|
|
2017-10-08 21:09:45 +00:00
|
|
|
// Array check if a string is in given array
|
|
|
|
func array(str string, list []string) bool {
|
2017-09-17 21:37:39 +00:00
|
|
|
for _, v := range list {
|
|
|
|
if v == str {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-10-08 21:09:45 +00:00
|
|
|
// Params parse one by one the given argumentes
|
|
|
|
func params(params *cli.Context) []string {
|
2016-08-31 12:08:15 +00:00
|
|
|
argsN := params.NArg()
|
|
|
|
if argsN > 0 {
|
|
|
|
var args []string
|
|
|
|
for i := 0; i <= argsN-1; i++ {
|
|
|
|
args = append(args, params.Args().Get(i))
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-09-17 21:37:39 +00:00
|
|
|
// Split each arguments in multiple fields
|
2017-10-08 21:09:45 +00:00
|
|
|
func split(args, fields []string) []string {
|
2017-09-17 21:37:39 +00:00
|
|
|
for _, arg := range fields {
|
|
|
|
arr := strings.Fields(arg)
|
|
|
|
args = append(args, arr...)
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
2016-08-31 12:08:15 +00:00
|
|
|
// Duplicates check projects with same name or same combinations of main/path
|
|
|
|
func duplicates(value Project, arr []Project) (Project, error) {
|
|
|
|
for _, val := range arr {
|
2017-10-08 21:09:45 +00:00
|
|
|
if value.Path == val.Path {
|
|
|
|
return val, errors.New("There is already a project with path '" + val.Path + "'. Check your config file!")
|
|
|
|
}
|
|
|
|
if value.Name == val.Name {
|
|
|
|
return val, errors.New("There is already a project with name '" + val.Name + "'. Check your config file!")
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Project{}, nil
|
|
|
|
}
|
|
|
|
|
2017-10-08 21:09:45 +00:00
|
|
|
func ext(path string) string {
|
|
|
|
var ext string
|
|
|
|
for i := len(path) - 1; i >= 0 && !os.IsPathSeparator(path[i]); i-- {
|
|
|
|
if path[i] == '.' {
|
|
|
|
ext = path[i:]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ext != "" {
|
|
|
|
return ext[1:]
|
|
|
|
}
|
|
|
|
return ""
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|