2017-11-19 23:52:31 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
2017-11-20 08:18:18 +00:00
|
|
|
"fmt"
|
2017-11-19 23:52:31 +00:00
|
|
|
)
|
|
|
|
|
2017-11-20 08:18:18 +00:00
|
|
|
// Schema projects list
|
2017-11-19 23:52:31 +00:00
|
|
|
type Schema struct {
|
2017-11-20 08:18:18 +00:00
|
|
|
Projects []Project `yaml:"schema" json:"schema"`
|
2017-11-19 23:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a project if unique
|
|
|
|
func (s *Schema) Add(p Project) {
|
|
|
|
for _, val := range s.Projects {
|
|
|
|
if reflect.DeepEqual(val, p) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Projects = append(s.Projects, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove a project
|
|
|
|
func (s *Schema) Remove(name string) error {
|
|
|
|
for key, val := range s.Projects {
|
|
|
|
if name == val.Name {
|
|
|
|
s.Projects = append(s.Projects[:key], s.Projects[key+1:]...)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errors.New("project not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
// New create a project using cli fields
|
|
|
|
func (s *Schema) New(c *cli.Context) Project {
|
|
|
|
name := filepath.Base(c.String("path"))
|
|
|
|
if name == "." {
|
|
|
|
name = filepath.Base(wdir())
|
|
|
|
}
|
|
|
|
project := Project{
|
|
|
|
Name: name,
|
|
|
|
Path: c.String("path"),
|
|
|
|
Tools: Tools{
|
|
|
|
Vet: Tool{
|
|
|
|
Status: c.Bool("vet"),
|
|
|
|
},
|
|
|
|
Fmt: Tool{
|
|
|
|
Status: c.Bool("fmt"),
|
|
|
|
},
|
|
|
|
Test: Tool{
|
|
|
|
Status: c.Bool("test"),
|
|
|
|
},
|
|
|
|
Generate: Tool{
|
|
|
|
Status: c.Bool("generate"),
|
|
|
|
},
|
|
|
|
Build: Tool{
|
|
|
|
Status: c.Bool("build"),
|
|
|
|
},
|
|
|
|
Install: Tool{
|
|
|
|
Status: c.Bool("install"),
|
|
|
|
},
|
|
|
|
Run: c.Bool("run"),
|
|
|
|
},
|
|
|
|
Args: params(c),
|
|
|
|
Watcher: Watch{
|
|
|
|
Paths: []string{"/"},
|
|
|
|
Ignore: []string{".git", ".realize", "vendor"},
|
|
|
|
Exts: []string{"go"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return project
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter project list by field
|
|
|
|
func (s *Schema) Filter(field string, value interface{}) {}
|