Compare commits

..

41 Commits

Author SHA1 Message Date
4df53b0b1b Merge pull request 'fix(deps): update module github.com/spf13/cobra to v1.8.1' (#6) from renovate/github.com-spf13-cobra-1.x into master
Reviewed-on: #6
2024-07-07 16:12:52 +00:00
Renovate Bot
80ad56859a fix(deps): update module github.com/spf13/cobra to v1.8.1 2024-07-06 14:22:35 -07:00
dda31be0bd Merge pull request 'fix(deps): update module github.com/fsnotify/fsnotify to v1.7.0' (#5) from renovate/github.com-fsnotify-fsnotify-1.x into master
Reviewed-on: #5
2024-07-06 21:06:16 +00:00
c241c301eb Merge pull request 'fix(deps): update module golang.org/x/net to v0.27.0' (#7) from renovate/golang.org-x-net-0.x into master
Reviewed-on: #7
2024-07-06 21:06:10 +00:00
9c5d8c6880 Merge pull request 'fix(deps): update module gopkg.in/yaml.v2 to v3' (#8) from renovate/gopkg.in-yaml.v2-3.x into master
Reviewed-on: #8
2024-07-06 21:06:07 +00:00
Renovate Bot
cdad1d23a9 fix(deps): update module gopkg.in/yaml.v2 to v3 2024-07-06 13:50:00 -07:00
Renovate Bot
032b1c4963 fix(deps): update module golang.org/x/net to v0.27.0 2024-07-06 13:49:57 -07:00
Renovate Bot
8f507fc092 fix(deps): update module github.com/fsnotify/fsnotify to v1.7.0 2024-07-06 13:49:49 -07:00
3f7815e571 Update renovate.json 2024-07-06 20:35:58 +00:00
7eb6f55084 Merge pull request 'chore(deps): update module github.com/sirupsen/logrus to v1.9.3' (#2) from renovate/github.com-sirupsen-logrus-1.x into master
Reviewed-on: #2
2024-07-06 20:25:57 +00:00
04bc1855f0 Merge pull request 'chore(deps): update module github.com/fatih/color to v1.17.0' (#3) from renovate/github.com-fatih-color-1.x into master
Reviewed-on: #3
2024-07-06 20:25:49 +00:00
Renovate Bot
275eca953b chore(deps): update module github.com/fatih/color to v1.17.0 2024-07-06 13:18:50 -07:00
Renovate Bot
47da49d37a chore(deps): update module github.com/sirupsen/logrus to v1.9.3 2024-07-06 13:18:47 -07:00
edb8acb6dc Merge pull request 'chore: Configure Renovate' (#1) from renovate/configure into master
Reviewed-on: #1
2024-07-06 20:11:15 +00:00
Renovate Bot
99a1463cfc Add renovate.json 2024-07-06 13:09:31 -07:00
8cf145955c
docs: version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-11 21:35:03 -08:00
62c1714958
updates
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-10 09:59:19 -08:00
49effe24b4
update urls 2023-03-09 23:48:25 -08:00
0f19f085ff
docs: version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-08 15:16:52 -08:00
7fa2e67a89
docs: readme
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-08 15:16:39 -08:00
0a0c88f25d
feat: per script environmental variables
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-08 15:14:45 -08:00
4992e63edb
docs: version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-08 13:47:07 -08:00
32d1074fd9
improved: aliases
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-08 13:46:44 -08:00
8f9ff1dada
docs: readme
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-08 13:22:04 -08:00
ec35355705
docs: readme
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-08 13:07:06 -08:00
40203011d5 fix: fix makefile
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-06 17:49:03 -08:00
2d893b57c2 doc: version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-06 11:02:52 -08:00
4e854075df improved: make haunt run generate default config if none found
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-06 11:02:34 -08:00
0e454d971d ci: add site unpacking / packing to makefile, ignore assets directory
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-06 10:39:51 -08:00
764265ba04 docs: version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-06 10:18:00 -08:00
8dd9007194 remove
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-06 10:17:39 -08:00
ee43417bb5 server redo 2023-03-06 10:17:28 -08:00
8805406e51 version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-05 23:58:07 -08:00
55e3fe4fca fix: remove debug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-05 23:57:48 -08:00
d7c1169e39 docs: version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-05 23:54:50 -08:00
b06ee1d6d7 fix: fix build/install
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-05 23:54:34 -08:00
f0c93b4fde docs: readme
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-05 23:52:48 -08:00
0279e65cee version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-05 23:48:13 -08:00
91a2115a18 version bump
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-05 23:47:44 -08:00
a5adf4c85e docs: update docs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2023-03-05 23:47:02 -08:00
6e515d040a clean
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-03-05 23:39:01 -08:00
20 changed files with 436 additions and 252 deletions

1
.gitignore vendored
View File

@ -25,6 +25,7 @@ _testmain.go
*.exe *.exe
*.test *.test
*.prof *.prof
/assets/
.glide .glide
.idea .idea

View File

@ -1,6 +1,6 @@
gitea_urls: gitea_urls:
api: https://gitea.asdf.cafe/api/v1 api: https://git.asdf.cafe/api/v1
download: https://gitea.asdf.cafe download: https://git.asdf.cafe
skip_tls_verify: false skip_tls_verify: false
before: before:

View File

@ -5,6 +5,12 @@ ${pkgname}: $(shell find . -name '*.go')
mkdir -p bin mkdir -p bin
go build -o bin/${pkgname} . go build -o bin/${pkgname} .
decode:
go run ./hack/unpack/main.go
pack-site:
go-bindata -pkg haunt -o src/haunt/bindata.go -fs assets/...
completions: completions:
mkdir -p completions mkdir -p completions
./bin/${pkgname} completion zsh > completions/_${pkgname} ./bin/${pkgname} completion zsh > completions/_${pkgname}
@ -18,17 +24,18 @@ tidy:
go mod tidy go mod tidy
clean: clean:
rm -f bin rm -rf bin
rm -rf completions rm -rf completions
rm -rf assets
uninstall: uninstall:
rm -f /usr/bin/${pkgname} rm -f /usr/local/bin/${pkgname}
rm -f /usr/share/zsh/site-functions/_${pkgname} rm -f /usr/share/zsh/site-functions/_${pkgname}
rm -f /usr/share/bash-completion/completions/${pkgname} rm -f /usr/share/bash-completion/completions/${pkgname}
rm -f /usr/share/fish/vendor_completions.d/${pkgname}.fish rm -f /usr/share/fish/vendor_completions.d/${pkgname}.fish
install: install:
cp bin/${pkgname} /usr/bin cp bin/${pkgname} /usr/local/bin
bin/${pkgname} completion zsh > /usr/share/zsh/site-functions/_${pkgname} bin/${pkgname} completion zsh > /usr/share/zsh/site-functions/_${pkgname}
bin/${pkgname} completion bash > /usr/share/bash-completion/completions/${pkgname} bin/${pkgname} completion bash > /usr/share/bash-completion/completions/${pkgname}
bin/${pkgname} completion fish > /usr/share/fish/vendor_completions.d/${pkgname}.fish bin/${pkgname} completion fish > /usr/share/fish/vendor_completions.d/${pkgname}.fish

102
README.md
View File

@ -1,4 +1,5 @@
## Quickstart ## Quickstart
### Install
``` ```
go install github.com/abs3ntdev/haunt@latest go install github.com/abs3ntdev/haunt@latest
``` ```
@ -11,58 +12,59 @@ cd haunt
make build && sudo make install make build && sudo make install
``` ```
#### aur
```
yay -S haunt-go-git
```
### Completions
completions will be automatically installed if you used the Makefile, if you did not you can generate completions with `haunt completion [bash/fish/powershell/zsh]`
for example: `haunt completion zsh > _haunt`
you can also source the output of the completion command directly in your .zshrc with:\
`source <(haunt completion zsh) && compdef _haunt haunt`
## Commands List ## Commands List
### Run Command
From **project/projects** root execute:
```
haunt init
```
then
```
haunt start
```
haunt init will add your root directory if it contains a main.go file and will add any directory inside of cmd as projects. If you wish to add additional projects run haunt add [name] or edit the config file manually. By default projects are set to run go install and go run [project]
***start*** command supports the following custom parameters:
--name="name" -> Run by name on existing configuration
--path="haunt/server" -> Custom Path (if not specified takes the working directory name)
--generate -> Enable go generate
--fmt -> Enable go fmt
--test -> Enable go test
--vet -> Enable go vet
--install -> Enable go install
--build -> Enable go build
--run -> Enable go run
--server -> Enable the web server
--open -> Open web ui in default browser
--no-config -> Ignore an existing config / skip the creation of a new one
Some examples:
haunt start
haunt start --path="mypath"
haunt start --name="haunt" --build
haunt start --path="haunt" --run --no-config
haunt start --install --test --fmt --no-config
haunt start --path="/Users/username/go/src/github.com/oxequa/haunt-examples/coin/"
### Init Command ### Init Command
This command will generate a .haunt.yaml with sane default for your current project/projects.\ This command will generate a .haunt.yaml with sane default for your current project/projects.\
If there is a main.go in the root directory it will be added along with any directories inside the relative path `cmd` If there is a main.go in the root directory it will be added along with any directories inside the relative path `cmd`
haunt init haunt init
### Add Command
Add a project to an existing config file or create a new one.
haunt add [name] ### Run Command
```
haunt run
```
the run command allows for specifying projects by name, all provided will be ran according to the config file:
Some examples:
haunt run
haunt run server api
### Add Command
Add a project, the same defaults init uses will be used for new projects unless flags are provided.
haunt add [name] [--flags]
Possible flags are:
-b, --build Enable go build
-f, --fmt Enable go fmt
-g, --generate Enable go generate
-h, --help help for add
-i, --install Enable go install (default true)
-p, --path string Project base path (default "./")
-r, --run Enable go run (default true)
-t, --test Enable go test
-v, --vet Enable go vet
### Remove Command ### Remove Command
Remove a project by its name Remove a project by its name
@ -88,7 +90,7 @@ Remove a project by its name
schema: schema:
- name: coin - name: coin
path: cmd/coin // project path path: cmd/coin // project path
env: // env variables available at startup env: // env variables for run
test: test test: test
myvar: value myvar: value
commands: // go commands supported commands: // go commands supported
@ -117,7 +119,8 @@ Remove a project by its name
- --myarg - --myarg
watcher: watcher:
paths: // watched paths are relative to directory you run haunt in paths: // watched paths are relative to directory you run haunt in
- / - src
- cmd/coin
ignore_paths: // ignored paths ignore_paths: // ignored paths
- vendor - vendor
extensions: // watched extensions extensions: // watched extensions
@ -128,14 +131,21 @@ Remove a project by its name
command: echo before global command: echo before global
global: true global: true
output: true output: true
env: // env variables per script
test: test
myvar: value
- type: before - type: before
command: echo before change command: echo before change
output: true output: true
env: // env variables per script
test: othertest
myvar: othervalue
- type: after - type: after
command: echo after change command: echo after change
output: true output: true
env: // env variables per script
key: 1
- type: after - type: after
command: echo after global command: echo after global
global: true global: true
output: true output: true
errorOutputPattern: mypattern //custom error pattern

View File

@ -14,6 +14,7 @@ var addConfig config.Flags
var addCmd = &cobra.Command{ var addCmd = &cobra.Command{
Use: "add", Use: "add",
Aliases: []string{"a", "create", "new"},
Short: "Adds a project by name", Short: "Adds a project by name",
Long: "Adds a project by name, if path is provided it will use 'cmd/name', all flags provided will be saved in the config file. By default go install and go run will be ran", Long: "Adds a project by name, if path is provided it will use 'cmd/name', all flags provided will be saved in the config file. By default go install and go run will be ran",
Args: cobra.MatchAll(cobra.ExactArgs(1)), Args: cobra.MatchAll(cobra.ExactArgs(1)),
@ -27,8 +28,8 @@ var addCmd = &cobra.Command{
} }
func getPotentialProjets(in string) []string { func getPotentialProjets(in string) []string {
r := haunt.NewHaunt() h := haunt.NewHaunt()
err := r.Settings.Read(&r) err := h.Settings.Read(&h)
if err != nil { if err != nil {
return []string{} return []string{}
} }
@ -39,7 +40,7 @@ func getPotentialProjets(in string) []string {
} }
for _, dir := range cmdDir { for _, dir := range cmdDir {
exists := false exists := false
for _, proj := range r.Projects { for _, proj := range h.Projects {
if dir.Name() == proj.Name { if dir.Name() == proj.Name {
exists = true exists = true
continue continue
@ -73,24 +74,24 @@ func init() {
// Add a project to an existing config or create a new one // Add a project to an existing config or create a new one
func add(cmd *cobra.Command, args []string) (err error) { func add(cmd *cobra.Command, args []string) (err error) {
addConfig.Name = args[0] addConfig.Name = args[0]
r := haunt.NewHaunt() h := haunt.NewHaunt()
// read a config if exist // read a config if exist
err = r.Settings.Read(&r) err = h.Settings.Read(&h)
if err != nil { if err != nil {
return err return err
} }
projects := len(r.Projects) projects := len(h.Projects)
// create and add a new project // create and add a new project
r.Add(r.New(addConfig)) h.Add(h.New(addConfig))
if len(r.Projects) > projects { if len(h.Projects) > projects {
// update config // update config
err = r.Settings.Write(r) err = h.Settings.Write(h)
if err != nil { if err != nil {
return err return err
} }
log.Println(r.Prefix(haunt.Green.Bold("project successfully added"))) log.Println(h.Prefix(haunt.Green.Bold("project successfully added")))
} else { } else {
log.Println(r.Prefix(haunt.Green.Bold("project can't be added"))) log.Println(h.Prefix(haunt.Green.Bold("project can't be added")))
} }
return nil return nil
} }

View File

@ -10,6 +10,7 @@ import (
// cleanCmd represents the clean command // cleanCmd represents the clean command
var cleanCmd = &cobra.Command{ var cleanCmd = &cobra.Command{
Use: "clean", Use: "clean",
Aliases: []string{"c"},
Short: "Deletes the haunt config file", Short: "Deletes the haunt config file",
RunE: clean, RunE: clean,
} }
@ -20,10 +21,10 @@ func init() {
// Clean remove haunt file // Clean remove haunt file
func clean(cmd *cobra.Command, args []string) (err error) { func clean(cmd *cobra.Command, args []string) (err error) {
r := haunt.NewHaunt() h := haunt.NewHaunt()
if err := r.Settings.Remove(haunt.RFile); err != nil { if err := h.Settings.Remove(haunt.HFile); err != nil {
return err return err
} }
log.Println(r.Prefix(haunt.Green.Bold("config file removed successfully removed"))) log.Println(h.Prefix(haunt.Green.Bold("config file removed successfully removed")))
return nil return nil
} }

View File

@ -13,6 +13,7 @@ import (
// initCmd represents the init command // initCmd represents the init command
var initCmd = &cobra.Command{ var initCmd = &cobra.Command{
Use: "init", Use: "init",
Aliases: []string{"i"},
Short: "Generates a haunt config file using sane defaults", Short: "Generates a haunt config file using sane defaults",
Long: "Generates a haunt config file using sane defaults, haunt will look for a main.go file and any directories inside the relative path 'cmd' and add them all as projects", Long: "Generates a haunt config file using sane defaults, haunt will look for a main.go file and any directories inside the relative path 'cmd' and add them all as projects",
RunE: defaultConfig, RunE: defaultConfig,
@ -23,10 +24,10 @@ func init() {
} }
func defaultConfig(cmd *cobra.Command, args []string) error { func defaultConfig(cmd *cobra.Command, args []string) error {
r := haunt.NewHaunt() h := haunt.NewHaunt()
write := true write := true
if _, err := os.Stat(haunt.RFile); err == nil { if _, err := os.Stat(haunt.HFile); err == nil {
fmt.Print(r.Prefix("Config file exists. Overwire? " + haunt.Magenta.Bold("[y/n] ") + haunt.Green.Bold("(n) "))) fmt.Print(h.Prefix("Config file exists. Overwire? " + haunt.Magenta.Bold("[y/n] ") + haunt.Green.Bold("(n) ")))
var overwrite string var overwrite string
fmt.Scanf("%s", &overwrite) fmt.Scanf("%s", &overwrite)
write = false write = false
@ -36,15 +37,15 @@ func defaultConfig(cmd *cobra.Command, args []string) error {
} }
} }
if write { if write {
r.SetDefaults() h.SetDefaults()
err := r.Settings.Write(r) err := h.Settings.Write(h)
if err != nil { if err != nil {
return err return err
} }
log.Println(r.Prefix( log.Println(h.Prefix(
"Config file has successfully been saved at .haunt.yaml", "Config file has successfully been saved at .haunt.yaml",
)) ))
log.Println(r.Prefix( log.Println(h.Prefix(
"Run haunt add --help to see how to add more projects", "Run haunt add --help to see how to add more projects",
)) ))
return nil return nil

View File

@ -10,6 +10,7 @@ import (
var removeCmd = &cobra.Command{ var removeCmd = &cobra.Command{
Use: "remove [names]", Use: "remove [names]",
Aliases: []string{"delete", "r"},
Short: "Removes all projects by name from config file", Short: "Removes all projects by name from config file",
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs), Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
@ -23,14 +24,14 @@ func init() {
} }
func getProjectNames(input string) []string { func getProjectNames(input string) []string {
r := haunt.NewHaunt() h := haunt.NewHaunt()
// read a config if exist // read a config if exist
err := r.Settings.Read(&r) err := h.Settings.Read(&h)
if err != nil { if err != nil {
return []string{} return []string{}
} }
names := []string{} names := []string{}
for _, project := range r.Projects { for _, project := range h.Projects {
if strings.HasPrefix(project.Name, input) { if strings.HasPrefix(project.Name, input) {
names = append(names, project.Name) names = append(names, project.Name)
} }
@ -40,22 +41,22 @@ func getProjectNames(input string) []string {
// Remove a project from an existing config // Remove a project from an existing config
func remove(cmd *cobra.Command, args []string) (err error) { func remove(cmd *cobra.Command, args []string) (err error) {
r := haunt.NewHaunt() h := haunt.NewHaunt()
// read a config if exist // read a config if exist
err = r.Settings.Read(&r) err = h.Settings.Read(&h)
if err != nil { if err != nil {
return err return err
} }
for _, arg := range args { for _, arg := range args {
err = r.Remove(arg) err = h.Remove(arg)
if err != nil { if err != nil {
log.Println(r.Prefix(haunt.Red.Bold(arg + " project not found"))) log.Println(h.Prefix(haunt.Red.Bold(arg + " project not found")))
continue continue
} }
log.Println(r.Prefix(haunt.Green.Bold(arg + " successfully removed"))) log.Println(h.Prefix(haunt.Green.Bold(arg + " successfully removed")))
} }
// update config // update config
err = r.Settings.Write(r) err = h.Settings.Write(h)
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,36 +1,39 @@
package cmd package cmd
import ( import (
"fmt"
"log" "log"
"os"
"strings" "strings"
"github.com/abs3ntdev/haunt/src/haunt" "github.com/abs3ntdev/haunt/src/haunt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var runCmd = &cobra.Command{ var startCmd = &cobra.Command{
Use: "run", Use: "start",
Aliases: []string{"s", "run"},
Short: "run haunt, optionally provide the name of projects to only run those otherwise will run all configured projects", Short: "run haunt, optionally provide the name of projects to only run those otherwise will run all configured projects",
Args: cobra.MatchAll(cobra.OnlyValidArgs), Args: cobra.MatchAll(cobra.OnlyValidArgs),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return getProjectNamesToRun(toComplete), cobra.ShellCompDirectiveNoFileComp return getProjectNamesToRun(toComplete), cobra.ShellCompDirectiveNoFileComp
}, },
RunE: run, RunE: start,
} }
func init() { func init() {
rootCmd.AddCommand(runCmd) rootCmd.AddCommand(startCmd)
} }
func getProjectNamesToRun(input string) []string { func getProjectNamesToRun(input string) []string {
r := haunt.NewHaunt() h := haunt.NewHaunt()
// read a config if exist // read a config if exist
err := r.Settings.Read(&r) err := h.Settings.Read(&h)
if err != nil { if err != nil {
return []string{} return []string{}
} }
names := []string{} names := []string{}
for _, project := range r.Projects { for _, project := range h.Projects {
if strings.HasPrefix(project.Name, input) { if strings.HasPrefix(project.Name, input) {
names = append(names, project.Name) names = append(names, project.Name)
} }
@ -39,42 +42,54 @@ func getProjectNamesToRun(input string) []string {
} }
// haunt workflow // haunt workflow
func run(cmd *cobra.Command, args []string) (err error) { func start(cmd *cobra.Command, args []string) (err error) {
r := haunt.NewHaunt() h := haunt.NewHaunt()
// read a config if exist // read a config if exist
err = r.Settings.Read(&r) err = h.Settings.Read(&h)
if err != nil { if err != nil {
if os.IsNotExist(err) {
log.Println(h.Prefix("No config file found, initializing one for you"))
err = defaultConfig(cmd, args)
if err != nil {
log.Println(h.Prefix("Failed to generate default config: " + err.Error()))
}
err = h.Settings.Read(&h)
if err != nil {
return fmt.Errorf(h.Prefix("Failed to read config file: " + err.Error()))
}
} else {
return err return err
} }
}
if len(args) >= 1 { if len(args) >= 1 {
// filter by name flag if exist // filter by name flag if exist
r.Projects = r.Filter(args) h.Projects = h.Filter(args)
if len(r.Projects) == 0 { if len(h.Projects) == 0 {
log.Println(r.Prefix("No valid project found, exiting. Check your config file or run haunt add")) log.Println(h.Prefix("No valid project found, exiting. Check your config file or run haunt add"))
return return
} }
} }
// increase file limit // increase file limit
if r.Settings.FileLimit != 0 { if h.Settings.FileLimit != 0 {
if err = r.Settings.Flimit(); err != nil { if err = h.Settings.Flimit(); err != nil {
return err return err
} }
} }
// web server // web server
if r.Server.Status { if h.Server.Status {
r.Server.Parent = r h.Server.Parent = h
err = r.Server.Start() err = h.Server.Start()
if err != nil { if err != nil {
return err return err
} }
err = r.Server.OpenURL() err = h.Server.OpenURL()
if err != nil { if err != nil {
return err return err
} }
} }
// run workflow // start workflow
return r.Run() return h.Start()
} }

View File

@ -7,18 +7,12 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var Version = "v0.1.13" var Version = "v0.2.11"
// versionCmd represents the version command // versionCmd represents the version command
var versionCmd = &cobra.Command{ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "A brief description of your command", Short: "Prints current verison",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: version, Run: version,
} }
@ -38,6 +32,6 @@ func init() {
// Version print current version // Version print current version
func version(cmd *cobra.Command, args []string) { func version(cmd *cobra.Command, args []string) {
r := haunt.NewHaunt() h := haunt.NewHaunt()
log.Println(r.Prefix(haunt.Green.Bold(Version))) log.Println(h.Prefix(haunt.Green.Bold(Version)))
} }

19
go.mod
View File

@ -3,13 +3,14 @@ module github.com/abs3ntdev/haunt
go 1.19 go 1.19
require ( require (
github.com/fatih/color v1.14.1 github.com/fatih/color v1.17.0
github.com/fsnotify/fsnotify v1.6.0 github.com/fsnotify/fsnotify v1.7.0
github.com/labstack/echo v3.3.10+incompatible github.com/labstack/echo v3.3.10+incompatible
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.6.1 github.com/spf13/cobra v1.8.1
golang.org/x/net v0.7.0 golang.org/x/net v0.27.0
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
) )
require ( require (
@ -17,12 +18,12 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.1 // indirect github.com/stretchr/testify v1.8.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.6.0 // indirect golang.org/x/crypto v0.25.0 // indirect
golang.org/x/sys v0.5.0 // indirect golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.7.0 // indirect golang.org/x/text v0.16.0 // indirect
) )

22
go.sum
View File

@ -1,4 +1,5 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -6,8 +7,12 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w= github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg= github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
@ -22,13 +27,19 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -46,8 +57,12 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -56,8 +71,15 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=

22
hack/unpack/main.go Normal file
View File

@ -0,0 +1,22 @@
package main
import (
"fmt"
"github.com/abs3ntdev/haunt/src/haunt"
)
func main() {
names := haunt.AssetNames()
fmt.Println("Assets in bindata:")
fmt.Println(names)
wd := "assets"
for i, v := range names {
fmt.Printf("Restoring asset [%v] [%s]\n", i, v)
err := haunt.RestoreAsset(wd, v)
if err != nil {
fmt.Println("Failed to restore", v)
}
}
}

View File

@ -3,5 +3,14 @@ package main
import "github.com/abs3ntdev/haunt/cmd" import "github.com/abs3ntdev/haunt/cmd"
func main() { func main() {
// names := haunt.AssetNames()
// fmt.Println("Assets in bindata:")
// fmt.Println(names)
//
// wd := "www"
// for i, v := range names {
// fmt.Printf("Restoring asset [%v] [%s]\n", i, v)
// haunt.RestoreAsset(wd, v)
// }
cmd.Execute() cmd.Execute()
} }

3
renovate.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": ["config:recommended"]
}

File diff suppressed because one or more lines are too long

View File

@ -16,14 +16,14 @@ import (
) )
var ( var (
// RPrefix tool name // HPrefix tool name
RPrefix = "haunt" HPrefix = "haunt"
// RExt file extension // HExt file extension
RExt = ".yaml" HExt = ".yaml"
// RFile config file name // HFile config file name
RFile = "." + RPrefix + RExt HFile = "." + HPrefix + HExt
// RExtWin windows extension // HExtWin windows extension
RExtWin = ".exe" HExtWin = ".exe"
) )
type ( type (
@ -76,17 +76,17 @@ func init() {
} }
} }
func (r *Haunt) SetDefaults() { func (h *Haunt) SetDefaults() {
r.Server = Server{Parent: r, Status: true, Open: false, Port: Port} h.Server = Server{Parent: h, Status: true, Open: false, Port: Port}
r.Settings.FileLimit = 0 h.Settings.FileLimit = 0
r.Settings.Legacy.Interval = 100 * time.Millisecond h.Settings.Legacy.Interval = 100 * time.Millisecond
r.Settings.Legacy.Force = false h.Settings.Legacy.Force = false
r.Settings.Errors = Resource{Name: FileErr, Status: false} h.Settings.Errors = Resource{Name: FileErr, Status: false}
r.Settings.Errors = Resource{Name: FileOut, Status: false} h.Settings.Errors = Resource{Name: FileOut, Status: false}
r.Settings.Errors = Resource{Name: FileLog, Status: false} h.Settings.Errors = Resource{Name: FileLog, Status: false}
if _, err := os.Stat("main.go"); err == nil { if _, err := os.Stat("main.go"); err == nil {
log.Println(r.Prefix(Green.Bold("Adding: " + filepath.Base(Wdir())))) log.Println(h.Prefix(Green.Bold("Adding: " + filepath.Base(Wdir()))))
r.Projects = append(r.Projects, Project{ h.Projects = append(h.Projects, Project{
Name: filepath.Base(Wdir()), Name: filepath.Base(Wdir()),
Path: Wdir(), Path: Wdir(),
Tools: Tools{ Tools: Tools{
@ -103,17 +103,17 @@ func (r *Haunt) SetDefaults() {
}, },
}) })
} else { } else {
log.Println(r.Prefix(Magenta.Bold("Skipping: " + filepath.Base(Wdir()) + " no main.go file in root"))) log.Println(h.Prefix(Magenta.Bold("Skipping: " + filepath.Base(Wdir()) + " no main.go file in root")))
} }
subDirs, err := os.ReadDir("cmd") subDirs, err := os.ReadDir("cmd")
if err != nil { if err != nil {
log.Println(r.Prefix("cmd directory not found, skipping")) log.Println(h.Prefix("cmd directory not found, skipping"))
return return
} }
for _, dir := range subDirs { for _, dir := range subDirs {
if dir.IsDir() { if dir.IsDir() {
log.Println(r.Prefix(Green.Bold("Adding: " + dir.Name()))) log.Println(h.Prefix(Green.Bold("Adding: " + dir.Name())))
r.Projects = append(r.Projects, Project{ h.Projects = append(h.Projects, Project{
Name: dir.Name(), Name: dir.Name(),
Path: "cmd/" + dir.Name(), Path: "cmd/" + dir.Name(),
Tools: Tools{ Tools: Tools{
@ -130,31 +130,31 @@ func (r *Haunt) SetDefaults() {
}, },
}) })
} else { } else {
log.Println(r.Prefix(Magenta.Bold("Skipping: " + dir.Name() + " not a directory"))) log.Println(h.Prefix(Magenta.Bold("Skipping: " + dir.Name() + " not a directory")))
} }
} }
} }
// Stop haunt workflow // Stop haunt workflow
func (r *Haunt) Stop() error { func (h *Haunt) Stop() error {
for k := range r.Projects { for k := range h.Projects {
if r.Schema.Projects[k].exit != nil { if h.Schema.Projects[k].exit != nil {
close(r.Schema.Projects[k].exit) close(h.Schema.Projects[k].exit)
} }
} }
return nil return nil
} }
// Run haunt workflow // Start haunt workflow
func (r *Haunt) Run() error { func (h *Haunt) Start() error {
if len(r.Projects) > 0 { if len(h.Projects) > 0 {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(len(r.Projects)) wg.Add(len(h.Projects))
for k := range r.Projects { for k := range h.Projects {
r.Schema.Projects[k].exit = make(chan os.Signal, 1) h.Schema.Projects[k].exit = make(chan os.Signal, 1)
signal.Notify(r.Schema.Projects[k].exit, os.Interrupt) signal.Notify(h.Schema.Projects[k].exit, os.Interrupt)
r.Schema.Projects[k].parent = r h.Schema.Projects[k].parent = h
go r.Schema.Projects[k].Watch(&wg) go h.Schema.Projects[k].Watch(&wg)
} }
wg.Wait() wg.Wait()
} else { } else {
@ -164,9 +164,9 @@ func (r *Haunt) Run() error {
} }
// Prefix a given string with tool name // Prefix a given string with tool name
func (r *Haunt) Prefix(input string) string { func (h *Haunt) Prefix(input string) string {
if len(input) > 0 { if len(input) > 0 {
return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(RPrefix), Yellow.Bold("]"), ": ", input) return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(HPrefix), Yellow.Bold("]"), ": ", input)
} }
return input return input
} }

View File

@ -43,6 +43,7 @@ type Ignore struct {
type Command struct { type Command struct {
Cmd string `yaml:"command" json:"command"` Cmd string `yaml:"command" json:"command"`
Type string `yaml:"type" json:"type"` Type string `yaml:"type" json:"type"`
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Path string `yaml:"path,omitempty" json:"path,omitempty"` Path string `yaml:"path,omitempty" json:"path,omitempty"`
Global bool `yaml:"global,omitempty" json:"global,omitempty"` Global bool `yaml:"global,omitempty" json:"global,omitempty"`
Output bool `yaml:"output,omitempty" json:"output,omitempty"` Output bool `yaml:"output,omitempty" json:"output,omitempty"`
@ -542,7 +543,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "out": case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o) p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.parent.Settings.Files.Outputs.Status { if p.parent.Settings.Files.Outputs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Outputs.Name) f := p.parent.Settings.Create(p.Path, p.parent.Settings.Outputs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil { if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "") p.parent.Settings.Fatal(err, "")
} }
@ -550,7 +551,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "log": case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o) p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.parent.Settings.Files.Logs.Status { if p.parent.Settings.Files.Logs.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Logs.Name) f := p.parent.Settings.Create(p.Path, p.parent.Settings.Logs.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil { if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "") p.parent.Settings.Fatal(err, "")
} }
@ -558,7 +559,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "error": case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o) p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.parent.Settings.Files.Errors.Status { if p.parent.Settings.Files.Errors.Status {
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.Errors.Name) f := p.parent.Settings.Create(p.Path, p.parent.Settings.Errors.Name)
if _, err := f.WriteString(strings.Join(content, " ")); err != nil { if _, err := f.WriteString(strings.Join(content, " ")); err != nil {
p.parent.Settings.Fatal(err, "") p.parent.Settings.Fatal(err, "")
} }
@ -577,7 +578,14 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
func (p Project) buildEnvs() (envs []string) { func (p Project) buildEnvs() (envs []string) {
for k, v := range p.Env { for k, v := range p.Env {
envs = append(envs, fmt.Sprintf("%s=%s", strings.Replace(k, "=", "", -1), v)) envs = append(envs, fmt.Sprintf("%s=%s", strings.ReplaceAll(k, "=", ""), v))
}
return
}
func (c Command) buildEnvs() (envs []string) {
for k, v := range c.Env {
envs = append(envs, fmt.Sprintf("%s=%s", strings.ReplaceAll(k, "=", ""), v))
} }
return return
} }
@ -637,13 +645,13 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err
} }
if _, err = os.Stat(path); err == nil { if _, err = os.Stat(path); err == nil {
build = exec.Command(path, args...) build = exec.Command(path, args...)
} else if _, err = os.Stat(path + RExtWin); err == nil { } else if _, err = os.Stat(path + HExtWin); err == nil {
build = exec.Command(path+RExtWin, args...) build = exec.Command(path+HExtWin, args...)
} else { } else {
if _, err = os.Stat(path); err == nil { if _, err = os.Stat(path); err == nil {
build = exec.Command(path, args...) build = exec.Command(path, args...)
} else if _, err = os.Stat(path + RExtWin); err == nil { } else if _, err = os.Stat(path + HExtWin); err == nil {
build = exec.Command(path+RExtWin, args...) build = exec.Command(path+HExtWin, args...)
} else { } else {
return errors.New("project not found") return errors.New("project not found")
} }
@ -715,6 +723,10 @@ func (c *Command) exec(base string, stop <-chan bool) (response Response) {
done := make(chan error) done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(c.Cmd, "'", "", -1), "\"", "", -1), " ") args := strings.Split(strings.Replace(strings.Replace(c.Cmd, "'", "", -1), "\"", "", -1), " ")
ex := exec.Command(args[0], args[1:]...) ex := exec.Command(args[0], args[1:]...)
appendEnvs := c.buildEnvs()
if len(appendEnvs) > 0 {
ex.Env = append(ex.Env, appendEnvs...)
}
ex.Dir = base ex.Dir = base
// make cmd path // make cmd path
if c.Path != "" { if c.Path != "" {

View File

@ -13,9 +13,9 @@ import (
const ( const (
Permission = 0o775 Permission = 0o775
File = ".haunt.yaml" File = ".haunt.yaml"
FileOut = ".r.outputs.log" FileOut = ".h.outputs.log"
FileErr = ".r.errors.log" FileErr = ".h.errors.log"
FileLog = ".r.logs.log" FileLog = ".h.logs.log"
) )
// Settings defines a group of general settings and options // Settings defines a group of general settings and options
@ -71,10 +71,10 @@ func (s *Settings) Remove(d string) error {
// Read config file // Read config file
func (s *Settings) Read(out interface{}) error { func (s *Settings) Read(out interface{}) error {
// backward compatibility // backward compatibility
if _, err := os.Stat(RFile); err != nil { if _, err := os.Stat(HFile); err != nil {
return err return err
} }
content, err := s.Stream(RFile) content, err := s.Stream(HFile)
if err == nil { if err == nil {
err = yaml.Unmarshal(content, out) err = yaml.Unmarshal(content, out)
return err return err
@ -88,7 +88,7 @@ func (s *Settings) Write(out interface{}) error {
if err != nil { if err != nil {
return err return err
} }
s.Fatal(os.WriteFile(RFile, y, Permission)) s.Fatal(os.WriteFile(HFile, y, Permission))
return nil return nil
} }

View File

@ -183,14 +183,8 @@ 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)
buildPath, _ := filepath.Abs(Wdir()) args := append(t.cmd, t.Args...)
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 {