fix: defaults should not be /
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d7b13f16ca
commit
42922c97b2
2
.gitignore
vendored
2
.gitignore
vendored
@ -29,7 +29,7 @@ _testmain.go
|
|||||||
.glide
|
.glide
|
||||||
.idea
|
.idea
|
||||||
.DS_Store
|
.DS_Store
|
||||||
haunt
|
.haunt
|
||||||
|
|
||||||
docker
|
docker
|
||||||
vendor
|
vendor
|
||||||
|
11
cmd/add.go
11
cmd/add.go
@ -60,7 +60,7 @@ func getPotentialProjets(in string) []string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(addCmd)
|
rootCmd.AddCommand(addCmd)
|
||||||
addCmd.Flags().StringVarP(&addConfig.Path, "path", "p", "", "Project base path")
|
addCmd.Flags().StringVarP(&addConfig.Path, "path", "p", "./", "Project base path")
|
||||||
addCmd.Flags().BoolVarP(&addConfig.Format, "fmt", "f", false, "Enable go fmt")
|
addCmd.Flags().BoolVarP(&addConfig.Format, "fmt", "f", false, "Enable go fmt")
|
||||||
addCmd.Flags().BoolVarP(&addConfig.Vet, "vet", "v", false, "Enable go vet")
|
addCmd.Flags().BoolVarP(&addConfig.Vet, "vet", "v", false, "Enable go vet")
|
||||||
addCmd.Flags().BoolVarP(&addConfig.Test, "test", "t", false, "Enable go test")
|
addCmd.Flags().BoolVarP(&addConfig.Test, "test", "t", false, "Enable go test")
|
||||||
@ -79,13 +79,10 @@ func add(cmd *cobra.Command, args []string) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if addConfig.Path == "" {
|
projects := len(r.Projects)
|
||||||
addConfig.Path = "cmd/" + addConfig.Name
|
|
||||||
}
|
|
||||||
projects := len(r.Schema.Projects)
|
|
||||||
// create and add a new project
|
// create and add a new project
|
||||||
r.Schema.Add(r.Schema.New(addConfig))
|
r.Add(r.New(addConfig))
|
||||||
if len(r.Schema.Projects) > projects {
|
if len(r.Projects) > projects {
|
||||||
// update config
|
// update config
|
||||||
err = r.Settings.Write(r)
|
err = r.Settings.Write(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,7 +30,7 @@ func getProjectNames(input string) []string {
|
|||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for _, project := range r.Schema.Projects {
|
for _, project := range r.Projects {
|
||||||
if strings.HasPrefix(project.Name, input) {
|
if strings.HasPrefix(project.Name, input) {
|
||||||
names = append(names, project.Name)
|
names = append(names, project.Name)
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func remove(cmd *cobra.Command, args []string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
err := r.Schema.Remove(arg)
|
err := r.Remove(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(r.Prefix(haunt.Red.Bold(arg + " project not found")))
|
log.Println(r.Prefix(haunt.Red.Bold(arg + " project not found")))
|
||||||
continue
|
continue
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/abs3ntdev/haunt/src/config"
|
"github.com/abs3ntdev/haunt/src/config"
|
||||||
@ -23,7 +23,7 @@ var startCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(startCmd)
|
rootCmd.AddCommand(startCmd)
|
||||||
startCmd.Flags().StringVarP(&startConfig.Path, "path", "p", "", "Project base path")
|
startCmd.Flags().StringVarP(&startConfig.Path, "path", "p", "./", "Project base path")
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Format, "fmt", "f", false, "Enable go fmt")
|
startCmd.Flags().BoolVarP(&startConfig.Format, "fmt", "f", false, "Enable go fmt")
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Vet, "vet", "v", false, "Enable go vet")
|
startCmd.Flags().BoolVarP(&startConfig.Vet, "vet", "v", false, "Enable go vet")
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Test, "test", "t", false, "Enable go test")
|
startCmd.Flags().BoolVarP(&startConfig.Test, "test", "t", false, "Enable go test")
|
||||||
@ -54,7 +54,7 @@ func getProjectNamesToStart(input string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start haunt workflow
|
// Start haunt workflow
|
||||||
func start(_ *cobra.Command, args []string) (err error) {
|
func start(cmd *cobra.Command, args []string) (err error) {
|
||||||
r := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
// set legacy watcher
|
// set legacy watcher
|
||||||
if startConfig.Legacy {
|
if startConfig.Legacy {
|
||||||
@ -76,9 +76,10 @@ func start(_ *cobra.Command, args []string) (err error) {
|
|||||||
// filter by name flag if exist
|
// filter by name flag if exist
|
||||||
r.Projects = r.Filter(args)
|
r.Projects = r.Filter(args)
|
||||||
if len(r.Projects) == 0 {
|
if len(r.Projects) == 0 {
|
||||||
fmt.Println("Project not found, exiting")
|
log.Println(r.Prefix("Project not found, exiting"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
startConfig.Name = args[0]
|
||||||
}
|
}
|
||||||
// increase file limit
|
// increase file limit
|
||||||
if r.Settings.FileLimit != 0 {
|
if r.Settings.FileLimit != 0 {
|
||||||
|
@ -99,7 +99,7 @@ func (r *Haunt) SetDefaults() {
|
|||||||
},
|
},
|
||||||
Watcher: Watch{
|
Watcher: Watch{
|
||||||
Exts: []string{"go"},
|
Exts: []string{"go"},
|
||||||
Paths: []string{"."},
|
Paths: []string{"./"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,8 +116,10 @@ func (p *Project) Before() {
|
|||||||
|
|
||||||
// setup go tools
|
// setup go tools
|
||||||
p.Tools.Setup(p)
|
p.Tools.Setup(p)
|
||||||
|
|
||||||
// global commands before
|
// global commands before
|
||||||
p.cmd(p.stop, "before", true)
|
p.cmd(p.stop, "before", true)
|
||||||
|
|
||||||
// indexing files and dirs
|
// indexing files and dirs
|
||||||
for _, dir := range p.Watcher.Paths {
|
for _, dir := range p.Watcher.Paths {
|
||||||
base, _ := filepath.Abs(dir)
|
base, _ := filepath.Abs(dir)
|
||||||
@ -127,6 +129,7 @@ func (p *Project) Before() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// start message
|
// start message
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Blue.Bold("Watching"), Magenta.Bold(p.files), "file/s", Magenta.Bold(p.folders), "folder/s")
|
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Blue.Bold("Watching"), Magenta.Bold(p.files), "file/s", Magenta.Bold(p.folders), "folder/s")
|
||||||
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(p.files, 10) + " files/s " + strconv.FormatInt(p.folders, 10) + " folder/s"}
|
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(p.files, 10) + " files/s " + strconv.FormatInt(p.folders, 10) + " folder/s"}
|
||||||
@ -139,6 +142,7 @@ func (p *Project) Err(err error) {
|
|||||||
p.parent.Err(Context{Project: p})
|
p.parent.Err(Context{Project: p})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Regular(err.Error()))
|
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Regular(err.Error()))
|
||||||
out = BufferOut{Time: time.Now(), Text: err.Error()}
|
out = BufferOut{Time: time.Now(), Text: err.Error()}
|
||||||
@ -169,6 +173,7 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
p.parent.Reload(Context{Project: p, Watcher: p.watcher, Path: path, Stop: stop})
|
p.parent.Reload(Context{Project: p, Watcher: p.watcher, Path: path, Stop: stop})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var done bool
|
var done bool
|
||||||
var install, build Response
|
var install, build Response
|
||||||
go func() {
|
go func() {
|
||||||
@ -178,14 +183,17 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if done {
|
if done {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// before command
|
// before command
|
||||||
p.cmd(stop, "before", false)
|
p.cmd(stop, "before", false)
|
||||||
if done {
|
if done {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go supported tools
|
// Go supported tools
|
||||||
if len(path) > 0 {
|
if len(path) > 0 {
|
||||||
fi, err := os.Stat(path)
|
fi, err := os.Stat(path)
|
||||||
@ -197,6 +205,7 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
}
|
}
|
||||||
p.tools(stop, path, fi)
|
p.tools(stop, path, fi)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent fake events on polling startup
|
// Prevent fake events on polling startup
|
||||||
p.init = true
|
p.init = true
|
||||||
// prevent errors using haunt without config with only run flag
|
// prevent errors using haunt without config with only run flag
|
||||||
@ -277,19 +286,24 @@ func (p *Project) Watch(wg *sync.WaitGroup) {
|
|||||||
var err error
|
var err error
|
||||||
// change channel
|
// change channel
|
||||||
p.stop = make(chan bool)
|
p.stop = make(chan bool)
|
||||||
|
|
||||||
// init a new watcher
|
// init a new watcher
|
||||||
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
|
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
close(p.stop)
|
close(p.stop)
|
||||||
p.watcher.Close()
|
p.watcher.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// before start checks
|
// before start checks
|
||||||
p.Before()
|
p.Before()
|
||||||
|
|
||||||
// start watcher
|
// start watcher
|
||||||
go p.Reload("", p.stop)
|
go p.Reload("", p.stop)
|
||||||
|
|
||||||
L:
|
L:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -2,6 +2,7 @@ package haunt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/abs3ntdev/haunt/src/config"
|
"github.com/abs3ntdev/haunt/src/config"
|
||||||
@ -35,6 +36,10 @@ func (s *Schema) Remove(name string) error {
|
|||||||
|
|
||||||
// New create a project using cli fields
|
// New create a project using cli fields
|
||||||
func (s *Schema) New(flags config.Flags) Project {
|
func (s *Schema) New(flags config.Flags) Project {
|
||||||
|
if flags.Name == "" {
|
||||||
|
flags.Name = Wdir()
|
||||||
|
}
|
||||||
|
fmt.Println(flags.Name)
|
||||||
project := Project{
|
project := Project{
|
||||||
Name: flags.Name,
|
Name: flags.Name,
|
||||||
Path: flags.Path,
|
Path: flags.Path,
|
||||||
@ -62,7 +67,7 @@ func (s *Schema) New(flags config.Flags) Project {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Watcher: Watch{
|
Watcher: Watch{
|
||||||
Paths: []string{"/"},
|
Paths: []string{"./"},
|
||||||
Ignore: []string{".git", ".haunt", "vendor"},
|
Ignore: []string{".git", ".haunt", "vendor"},
|
||||||
Exts: []string{"go"},
|
Exts: []string{"go"},
|
||||||
},
|
},
|
||||||
|
@ -202,7 +202,6 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
|
|||||||
log.Println(log.Prefix(), err.Error())
|
log.Println(log.Prefix(), err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
done <- cmd.Wait()
|
done <- cmd.Wait()
|
||||||
|
Loading…
Reference in New Issue
Block a user