improved: change default to install + run and change start -> run
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
d6c1b9704c
commit
712ef52265
@ -24,6 +24,6 @@ func clean(cmd *cobra.Command, args []string) (err error) {
|
|||||||
if err := r.Settings.Remove(haunt.RFile); err != nil {
|
if err := r.Settings.Remove(haunt.RFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println(r.Prefix(haunt.Green.Bold("folder successfully removed")))
|
log.Println(r.Prefix(haunt.Green.Bold("config file removed successfully removed")))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
80
cmd/run.go
Normal file
80
cmd/run.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/abs3ntdev/haunt/src/haunt"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var runCmd = &cobra.Command{
|
||||||
|
Use: "run",
|
||||||
|
Short: "run haunt, optionally provide the name of projects to only run those otherwise will run all configured projects",
|
||||||
|
Args: cobra.MatchAll(cobra.OnlyValidArgs),
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return getProjectNamesToRun(toComplete), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
RunE: run,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(runCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getProjectNamesToRun(input string) []string {
|
||||||
|
r := haunt.NewHaunt()
|
||||||
|
// read a config if exist
|
||||||
|
err := r.Settings.Read(&r)
|
||||||
|
if err != nil {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
names := []string{}
|
||||||
|
for _, project := range r.Projects {
|
||||||
|
if strings.HasPrefix(project.Name, input) {
|
||||||
|
names = append(names, project.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
// haunt workflow
|
||||||
|
func run(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
r := haunt.NewHaunt()
|
||||||
|
|
||||||
|
// read a config if exist
|
||||||
|
err = r.Settings.Read(&r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(args) >= 1 {
|
||||||
|
// filter by name flag if exist
|
||||||
|
r.Projects = r.Filter(args)
|
||||||
|
if len(r.Projects) == 0 {
|
||||||
|
log.Println(r.Prefix("No valid project found, exiting. Check your config file or run haunt add"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// increase file limit
|
||||||
|
if r.Settings.FileLimit != 0 {
|
||||||
|
if err = r.Settings.Flimit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// web server
|
||||||
|
if r.Server.Status {
|
||||||
|
r.Server.Parent = r
|
||||||
|
err = r.Server.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = r.Server.OpenURL()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run workflow
|
||||||
|
return r.Run()
|
||||||
|
}
|
120
cmd/start.go
120
cmd/start.go
@ -1,120 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/abs3ntdev/haunt/src/config"
|
|
||||||
"github.com/abs3ntdev/haunt/src/haunt"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var startConfig config.Flags
|
|
||||||
|
|
||||||
var startCmd = &cobra.Command{
|
|
||||||
Use: "start",
|
|
||||||
Short: "Start haunt on a given path, generates a config file if one does not already exist",
|
|
||||||
Args: cobra.MatchAll(cobra.OnlyValidArgs),
|
|
||||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
||||||
return getProjectNamesToStart(toComplete), cobra.ShellCompDirectiveNoFileComp
|
|
||||||
},
|
|
||||||
RunE: start,
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(startCmd)
|
|
||||||
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")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Generate, "generate", "g", false, "Enable go generate")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Server, "server", "s", false, "Start server")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Open, "open", "o", false, "Open into the default browser")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Install, "install", "i", true, "Enable go install")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Build, "build", "b", false, "Enable go build")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Run, "run", "r", true, "Enable go run")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.Legacy, "legacy", "l", false, "Legacy watch by polling instead fsnotify")
|
|
||||||
startCmd.Flags().BoolVarP(&startConfig.NoConfig, "no-config", "c", false, "Ignore existing config and doesn't create a new one")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getProjectNamesToStart(input string) []string {
|
|
||||||
r := haunt.NewHaunt()
|
|
||||||
// read a config if exist
|
|
||||||
err := r.Settings.Read(&r)
|
|
||||||
if err != nil {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
names := []string{}
|
|
||||||
for _, project := range r.Projects {
|
|
||||||
if strings.HasPrefix(project.Name, input) {
|
|
||||||
names = append(names, project.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return names
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start haunt workflow
|
|
||||||
func start(cmd *cobra.Command, args []string) (err error) {
|
|
||||||
r := haunt.NewHaunt()
|
|
||||||
// set legacy watcher
|
|
||||||
if startConfig.Legacy {
|
|
||||||
r.Settings.Legacy.Set(startConfig.Legacy, 1)
|
|
||||||
}
|
|
||||||
// set server
|
|
||||||
if startConfig.Server {
|
|
||||||
r.Server.Set(startConfig.Server, startConfig.Open, haunt.Port, haunt.Host)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check no-config and read
|
|
||||||
if !startConfig.NoConfig {
|
|
||||||
// read a config if exist
|
|
||||||
err = r.Settings.Read(&r)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(args) >= 1 {
|
|
||||||
// filter by name flag if exist
|
|
||||||
r.Projects = r.Filter(args)
|
|
||||||
if len(r.Projects) == 0 {
|
|
||||||
log.Println(r.Prefix("Project not found, exiting"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
startConfig.Name = args[0]
|
|
||||||
}
|
|
||||||
// increase file limit
|
|
||||||
if r.Settings.FileLimit != 0 {
|
|
||||||
if err = r.Settings.Flimit(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// check project list length
|
|
||||||
if len(r.Projects) == 0 {
|
|
||||||
// create a new project based on given params
|
|
||||||
project := r.New(startConfig)
|
|
||||||
// Add to projects list
|
|
||||||
r.Add(project)
|
|
||||||
// save config
|
|
||||||
if !startConfig.NoConfig {
|
|
||||||
err = r.Settings.Write(r)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Start web server
|
|
||||||
if r.Server.Status {
|
|
||||||
r.Server.Parent = r
|
|
||||||
err = r.Server.Start()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = r.Server.OpenURL()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// start workflow
|
|
||||||
return r.Start()
|
|
||||||
}
|
|
@ -120,9 +120,6 @@ func (r *Haunt) SetDefaults() {
|
|||||||
Install: Tool{
|
Install: Tool{
|
||||||
Status: true,
|
Status: true,
|
||||||
},
|
},
|
||||||
Build: Tool{
|
|
||||||
Status: true,
|
|
||||||
},
|
|
||||||
Run: Tool{
|
Run: Tool{
|
||||||
Status: true,
|
Status: true,
|
||||||
},
|
},
|
||||||
@ -148,8 +145,8 @@ func (r *Haunt) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start haunt workflow
|
// Run haunt workflow
|
||||||
func (r *Haunt) Start() error {
|
func (r *Haunt) Run() error {
|
||||||
if len(r.Projects) > 0 {
|
if len(r.Projects) > 0 {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(r.Projects))
|
wg.Add(len(r.Projects))
|
||||||
|
@ -183,8 +183,14 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
|
|||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
var stderr bytes.Buffer
|
var stderr bytes.Buffer
|
||||||
done := make(chan error)
|
done := make(chan error)
|
||||||
args := append(t.cmd, t.Args...)
|
buildPath, _ := filepath.Abs(Wdir())
|
||||||
|
buildPath = "-o " + buildPath
|
||||||
|
buildPath += "/bin"
|
||||||
|
fmt.Println(t.cmd, t.Args)
|
||||||
|
args := append(t.cmd, buildPath)
|
||||||
|
args = append(args, t.Args...)
|
||||||
cmd := exec.Command(args[0], args[1:]...)
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
fmt.Println(cmd)
|
||||||
if t.Dir != "" {
|
if t.Dir != "" {
|
||||||
cmd.Dir, _ = filepath.Abs(t.Dir)
|
cmd.Dir, _ = filepath.Abs(t.Dir)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user