fix: defaults should not be /
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
abs3nt 2023-03-05 14:28:09 -08:00
parent d7b13f16ca
commit 42922c97b2
8 changed files with 33 additions and 17 deletions

2
.gitignore vendored
View File

@ -29,7 +29,7 @@ _testmain.go
.glide
.idea
.DS_Store
haunt
.haunt
docker
vendor

View File

@ -60,7 +60,7 @@ func getPotentialProjets(in string) []string {
func init() {
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.Vet, "vet", "v", false, "Enable go vet")
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 {
return err
}
if addConfig.Path == "" {
addConfig.Path = "cmd/" + addConfig.Name
}
projects := len(r.Schema.Projects)
projects := len(r.Projects)
// create and add a new project
r.Schema.Add(r.Schema.New(addConfig))
if len(r.Schema.Projects) > projects {
r.Add(r.New(addConfig))
if len(r.Projects) > projects {
// update config
err = r.Settings.Write(r)
if err != nil {

View File

@ -30,7 +30,7 @@ func getProjectNames(input string) []string {
return []string{}
}
names := []string{}
for _, project := range r.Schema.Projects {
for _, project := range r.Projects {
if strings.HasPrefix(project.Name, input) {
names = append(names, project.Name)
}
@ -47,7 +47,7 @@ func remove(cmd *cobra.Command, args []string) (err error) {
return err
}
for _, arg := range args {
err := r.Schema.Remove(arg)
err := r.Remove(arg)
if err != nil {
log.Println(r.Prefix(haunt.Red.Bold(arg + " project not found")))
continue

View File

@ -1,7 +1,7 @@
package cmd
import (
"fmt"
"log"
"strings"
"github.com/abs3ntdev/haunt/src/config"
@ -23,7 +23,7 @@ var startCmd = &cobra.Command{
func init() {
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.Vet, "vet", "v", false, "Enable go vet")
startCmd.Flags().BoolVarP(&startConfig.Test, "test", "t", false, "Enable go test")
@ -54,7 +54,7 @@ func getProjectNamesToStart(input string) []string {
}
// Start haunt workflow
func start(_ *cobra.Command, args []string) (err error) {
func start(cmd *cobra.Command, args []string) (err error) {
r := haunt.NewHaunt()
// set legacy watcher
if startConfig.Legacy {
@ -76,9 +76,10 @@ func start(_ *cobra.Command, args []string) (err error) {
// filter by name flag if exist
r.Projects = r.Filter(args)
if len(r.Projects) == 0 {
fmt.Println("Project not found, exiting")
log.Println(r.Prefix("Project not found, exiting"))
return
}
startConfig.Name = args[0]
}
// increase file limit
if r.Settings.FileLimit != 0 {

View File

@ -99,7 +99,7 @@ func (r *Haunt) SetDefaults() {
},
Watcher: Watch{
Exts: []string{"go"},
Paths: []string{"."},
Paths: []string{"./"},
},
})
} else {

View File

@ -116,8 +116,10 @@ func (p *Project) Before() {
// setup go tools
p.Tools.Setup(p)
// global commands before
p.cmd(p.stop, "before", true)
// indexing files and dirs
for _, dir := range p.Watcher.Paths {
base, _ := filepath.Abs(dir)
@ -127,6 +129,7 @@ func (p *Project) Before() {
}
}
}
// 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")
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})
return
}
if err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Regular(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})
return
}
var done bool
var install, build Response
go func() {
@ -178,14 +183,17 @@ func (p *Project) Reload(path string, stop <-chan bool) {
return
}
}()
if done {
return
}
// before command
p.cmd(stop, "before", false)
if done {
return
}
// Go supported tools
if len(path) > 0 {
fi, err := os.Stat(path)
@ -197,6 +205,7 @@ func (p *Project) Reload(path string, stop <-chan bool) {
}
p.tools(stop, path, fi)
}
// Prevent fake events on polling startup
p.init = true
// prevent errors using haunt without config with only run flag
@ -277,19 +286,24 @@ func (p *Project) Watch(wg *sync.WaitGroup) {
var err error
// change channel
p.stop = make(chan bool)
// init a new watcher
p.watcher, err = NewFileWatcher(p.parent.Settings.Legacy)
if err != nil {
log.Fatal(err)
}
defer func() {
close(p.stop)
p.watcher.Close()
}()
// before start checks
p.Before()
// start watcher
go p.Reload("", p.stop)
L:
for {
select {

View File

@ -2,6 +2,7 @@ package haunt
import (
"errors"
"fmt"
"reflect"
"github.com/abs3ntdev/haunt/src/config"
@ -35,6 +36,10 @@ func (s *Schema) Remove(name string) error {
// New create a project using cli fields
func (s *Schema) New(flags config.Flags) Project {
if flags.Name == "" {
flags.Name = Wdir()
}
fmt.Println(flags.Name)
project := Project{
Name: flags.Name,
Path: flags.Path,
@ -62,7 +67,7 @@ func (s *Schema) New(flags config.Flags) Project {
},
},
Watcher: Watch{
Paths: []string{"/"},
Paths: []string{"./"},
Ignore: []string{".git", ".haunt", "vendor"},
Exts: []string{"go"},
},

View File

@ -202,7 +202,6 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
log.Println(log.Prefix(), err.Error())
}
}
os.Exit(0)
}
go func() {
done <- cmd.Wait()