2017-04-13 12:48:48 +00:00
|
|
|
package watcher
|
2016-08-31 12:08:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2017-06-19 09:29:30 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-08-31 12:08:15 +00:00
|
|
|
"time"
|
2017-04-13 12:48:48 +00:00
|
|
|
|
2017-04-13 13:49:51 +00:00
|
|
|
"github.com/tockins/realize/style"
|
2017-04-13 12:48:48 +00:00
|
|
|
cli "gopkg.in/urfave/cli.v2"
|
2017-09-03 18:00:40 +00:00
|
|
|
"strings"
|
2016-08-31 12:08:15 +00:00
|
|
|
)
|
|
|
|
|
2016-11-01 10:16:15 +00:00
|
|
|
// Argsparam parse one by one the given argumentes
|
2016-08-31 12:08:15 +00:00
|
|
|
func argsParam(params *cli.Context) []string {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-04-15 08:50:49 +00:00
|
|
|
if value.Path == val.Path && val.Name == value.Name {
|
2017-03-19 23:19:05 +00:00
|
|
|
return val, errors.New("There is already a project for '" + val.Path + "'. Check your config file!")
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Project{}, nil
|
|
|
|
}
|
|
|
|
|
2016-11-01 10:16:15 +00:00
|
|
|
// Check if a string is inArray
|
2016-08-31 12:08:15 +00:00
|
|
|
func inArray(str string, list []string) bool {
|
|
|
|
for _, v := range list {
|
|
|
|
if v == str {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2016-11-01 10:16:15 +00:00
|
|
|
// Rewrite the layout of the log timestamp
|
2016-11-01 09:56:12 +00:00
|
|
|
func (w logWriter) Write(bytes []byte) (int, error) {
|
2017-08-31 06:58:04 +00:00
|
|
|
return fmt.Fprint(style.Output, style.Yellow.Regular("[")+time.Now().Format("15:04:05")+style.Yellow.Regular("]")+string(bytes))
|
2016-08-31 12:08:15 +00:00
|
|
|
}
|
2017-06-19 09:29:30 +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 ""
|
|
|
|
}
|
2017-08-11 20:24:18 +00:00
|
|
|
return path[0]
|
2017-06-19 09:29:30 +00:00
|
|
|
}
|
2017-09-03 18:00:40 +00:00
|
|
|
|
|
|
|
// Split each arguments in multiple fields
|
|
|
|
func arguments(args, fields []string) []string {
|
|
|
|
for _, arg := range fields {
|
|
|
|
arr := strings.Fields(arg)
|
|
|
|
args = append(args, arr...)
|
|
|
|
}
|
|
|
|
return args
|
|
|
|
}
|