Compare commits
No commits in common. "master" and "v0.1.3" have entirely different histories.
@ -17,10 +17,6 @@ builds:
|
|||||||
ignore:
|
ignore:
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: "386"
|
goarch: "386"
|
||||||
# Custom ldflags templates.
|
|
||||||
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
|
|
||||||
ldflags:
|
|
||||||
- -s -w -X github.com/abs3ntdev/haunt/cmd.Version={{.Version}}
|
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- format: tar.gz
|
- format: tar.gz
|
||||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -25,14 +25,13 @@ _testmain.go
|
|||||||
*.exe
|
*.exe
|
||||||
*.test
|
*.test
|
||||||
*.prof
|
*.prof
|
||||||
/assets/
|
|
||||||
|
|
||||||
.glide
|
.glide
|
||||||
.idea
|
.idea
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/haunt/
|
.realize
|
||||||
/haunt
|
|
||||||
|
|
||||||
|
realize/assets/*
|
||||||
docker
|
docker
|
||||||
vendor
|
vendor
|
||||||
bin
|
bin
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
gitea_urls:
|
gitea_urls:
|
||||||
api: https://git.asdf.cafe/api/v1
|
api: https://gitea.asdf.cafe/api/v1
|
||||||
download: https://git.asdf.cafe
|
download: https://gitea.asdf.cafe
|
||||||
skip_tls_verify: false
|
skip_tls_verify: false
|
||||||
|
|
||||||
before:
|
before:
|
||||||
@ -17,10 +17,6 @@ builds:
|
|||||||
ignore:
|
ignore:
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: "386"
|
goarch: "386"
|
||||||
# Custom ldflags templates.
|
|
||||||
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
|
|
||||||
ldflags:
|
|
||||||
- -s -w -X github.com/abs3ntdev/haunt/cmd.Version={{.Version}}
|
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- format: tar.gz
|
- format: tar.gz
|
||||||
|
@ -4,9 +4,10 @@ pipeline:
|
|||||||
commands:
|
commands:
|
||||||
- go mod tidy
|
- go mod tidy
|
||||||
- go build -o bin/haunt
|
- go build -o bin/haunt
|
||||||
when:
|
- mkdir completions
|
||||||
event: push
|
- ./bin/haunt completion zsh > completions/haunt_zsh
|
||||||
|
- ./bin/haunt completion bash > completions/haunt_bash
|
||||||
|
- ./bin/haunt completion fish > completions/haunt_fish
|
||||||
publish:
|
publish:
|
||||||
image: goreleaser/goreleaser
|
image: goreleaser/goreleaser
|
||||||
commands:
|
commands:
|
||||||
|
13
Makefile
13
Makefile
@ -5,12 +5,6 @@ ${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}
|
||||||
@ -24,18 +18,17 @@ tidy:
|
|||||||
go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf bin
|
rm -f bin
|
||||||
rm -rf completions
|
rm -rf completions
|
||||||
rm -rf assets
|
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f /usr/local/bin/${pkgname}
|
rm -f /usr/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/local/bin
|
cp bin/${pkgname} /usr/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
|
||||||
|
100
README.md
100
README.md
@ -1,5 +1,4 @@
|
|||||||
## Quickstart
|
## Quickstart
|
||||||
### Install
|
|
||||||
```
|
```
|
||||||
go install github.com/abs3ntdev/haunt@latest
|
go install github.com/abs3ntdev/haunt@latest
|
||||||
```
|
```
|
||||||
@ -12,59 +11,58 @@ 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
|
||||||
|
|
||||||
|
|
||||||
### 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 Command
|
||||||
Add a project, the same defaults init uses will be used for new projects unless flags are provided.
|
Add a project to an existing config file or create a new one.
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
haunt add [name]
|
||||||
|
|
||||||
### Remove Command
|
### Remove Command
|
||||||
Remove a project by its name
|
Remove a project by its name
|
||||||
@ -90,7 +88,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 for run
|
env: // env variables available at startup
|
||||||
test: test
|
test: test
|
||||||
myvar: value
|
myvar: value
|
||||||
commands: // go commands supported
|
commands: // go commands supported
|
||||||
@ -119,8 +117,7 @@ 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
|
||||||
@ -131,21 +128,14 @@ 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
|
||||||
|
36
cmd/add.go
36
cmd/add.go
@ -13,11 +13,10 @@ import (
|
|||||||
var addConfig config.Flags
|
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)),
|
|
||||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
if len(args) >= 1 {
|
if len(args) >= 1 {
|
||||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
@ -28,8 +27,8 @@ var addCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getPotentialProjets(in string) []string {
|
func getPotentialProjets(in string) []string {
|
||||||
h := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
err := h.Settings.Read(&h)
|
err := r.Settings.Read(&r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
@ -40,7 +39,7 @@ func getPotentialProjets(in string) []string {
|
|||||||
}
|
}
|
||||||
for _, dir := range cmdDir {
|
for _, dir := range cmdDir {
|
||||||
exists := false
|
exists := false
|
||||||
for _, proj := range h.Projects {
|
for _, proj := range r.Projects {
|
||||||
if dir.Name() == proj.Name {
|
if dir.Name() == proj.Name {
|
||||||
exists = true
|
exists = true
|
||||||
continue
|
continue
|
||||||
@ -61,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")
|
||||||
@ -74,24 +73,27 @@ 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]
|
||||||
h := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
// read a config if exist
|
// read a config if exist
|
||||||
err = h.Settings.Read(&h)
|
err = r.Settings.Read(&r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
projects := len(h.Projects)
|
if addConfig.Path == "" {
|
||||||
|
addConfig.Path = "cmd/" + addConfig.Name
|
||||||
|
}
|
||||||
|
projects := len(r.Schema.Projects)
|
||||||
// create and add a new project
|
// create and add a new project
|
||||||
h.Add(h.New(addConfig))
|
r.Schema.Add(r.Schema.New(addConfig))
|
||||||
if len(h.Projects) > projects {
|
if len(r.Schema.Projects) > projects {
|
||||||
// update config
|
// update config
|
||||||
err = h.Settings.Write(h)
|
err = r.Settings.Write(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println(h.Prefix(haunt.Green.Bold("project successfully added")))
|
log.Println(r.Prefix(haunt.Green.Bold("project successfully added")))
|
||||||
} else {
|
} else {
|
||||||
log.Println(h.Prefix(haunt.Green.Bold("project can't be added")))
|
log.Println(r.Prefix(haunt.Green.Bold("project can't be added")))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
13
cmd/clean.go
13
cmd/clean.go
@ -9,10 +9,9 @@ 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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -21,10 +20,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) {
|
||||||
h := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
if err := h.Settings.Remove(haunt.HFile); err != nil {
|
if err := r.Settings.Remove(haunt.RFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println(h.Prefix(haunt.Green.Bold("config file removed successfully removed")))
|
log.Println(r.Prefix(haunt.Green.Bold("folder successfully removed")))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
23
cmd/init.go
23
cmd/init.go
@ -12,11 +12,10 @@ 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,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -24,10 +23,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func defaultConfig(cmd *cobra.Command, args []string) error {
|
func defaultConfig(cmd *cobra.Command, args []string) error {
|
||||||
h := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
write := true
|
write := true
|
||||||
if _, err := os.Stat(haunt.HFile); err == nil {
|
if _, err := os.Stat(haunt.RFile); err == nil {
|
||||||
fmt.Print(h.Prefix("Config file exists. Overwire? " + haunt.Magenta.Bold("[y/n] ") + haunt.Green.Bold("(n) ")))
|
fmt.Print(r.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
|
||||||
@ -37,15 +36,15 @@ func defaultConfig(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if write {
|
if write {
|
||||||
h.SetDefaults()
|
r.SetDefaults()
|
||||||
err := h.Settings.Write(h)
|
err := r.Settings.Write(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println(h.Prefix(
|
log.Println(r.Prefix(
|
||||||
"Config file has successfully been saved at .haunt.yaml",
|
"Config file has successfully been saved at .haunt.yaml",
|
||||||
))
|
))
|
||||||
log.Println(h.Prefix(
|
log.Println(r.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
|
||||||
|
@ -9,10 +9,9 @@ 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) {
|
||||||
return getProjectNames(toComplete), cobra.ShellCompDirectiveNoFileComp
|
return getProjectNames(toComplete), cobra.ShellCompDirectiveNoFileComp
|
||||||
},
|
},
|
||||||
@ -24,14 +23,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getProjectNames(input string) []string {
|
func getProjectNames(input string) []string {
|
||||||
h := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
// read a config if exist
|
// read a config if exist
|
||||||
err := h.Settings.Read(&h)
|
err := r.Settings.Read(&r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for _, project := range h.Projects {
|
for _, project := range r.Schema.Projects {
|
||||||
if strings.HasPrefix(project.Name, input) {
|
if strings.HasPrefix(project.Name, input) {
|
||||||
names = append(names, project.Name)
|
names = append(names, project.Name)
|
||||||
}
|
}
|
||||||
@ -41,22 +40,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) {
|
||||||
h := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
// read a config if exist
|
// read a config if exist
|
||||||
err = h.Settings.Read(&h)
|
err = r.Settings.Read(&r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
err = h.Remove(arg)
|
err := r.Schema.Remove(arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(h.Prefix(haunt.Red.Bold(arg + " project not found")))
|
log.Println(r.Prefix(haunt.Red.Bold(arg + " project not found")))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Println(h.Prefix(haunt.Green.Bold(arg + " successfully removed")))
|
log.Println(r.Prefix(haunt.Green.Bold(arg + " successfully removed")))
|
||||||
}
|
}
|
||||||
// update config
|
// update config
|
||||||
err = h.Settings.Write(h)
|
err = r.Settings.Write(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,8 +21,8 @@ var rootCmd = &cobra.Command{
|
|||||||
func Execute() {
|
func Execute() {
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
95
cmd/run.go
95
cmd/run.go
@ -1,95 +0,0 @@
|
|||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/abs3ntdev/haunt/src/haunt"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var startCmd = &cobra.Command{
|
|
||||||
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",
|
|
||||||
Args: cobra.MatchAll(cobra.OnlyValidArgs),
|
|
||||||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
||||||
return getProjectNamesToRun(toComplete), cobra.ShellCompDirectiveNoFileComp
|
|
||||||
},
|
|
||||||
RunE: start,
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(startCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getProjectNamesToRun(input string) []string {
|
|
||||||
h := haunt.NewHaunt()
|
|
||||||
// read a config if exist
|
|
||||||
err := h.Settings.Read(&h)
|
|
||||||
if err != nil {
|
|
||||||
return []string{}
|
|
||||||
}
|
|
||||||
names := []string{}
|
|
||||||
for _, project := range h.Projects {
|
|
||||||
if strings.HasPrefix(project.Name, input) {
|
|
||||||
names = append(names, project.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return names
|
|
||||||
}
|
|
||||||
|
|
||||||
// haunt workflow
|
|
||||||
func start(cmd *cobra.Command, args []string) (err error) {
|
|
||||||
h := haunt.NewHaunt()
|
|
||||||
|
|
||||||
// read a config if exist
|
|
||||||
err = h.Settings.Read(&h)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(args) >= 1 {
|
|
||||||
// filter by name flag if exist
|
|
||||||
h.Projects = h.Filter(args)
|
|
||||||
if len(h.Projects) == 0 {
|
|
||||||
log.Println(h.Prefix("No valid project found, exiting. Check your config file or run haunt add"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// increase file limit
|
|
||||||
if h.Settings.FileLimit != 0 {
|
|
||||||
if err = h.Settings.Flimit(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// web server
|
|
||||||
if h.Server.Status {
|
|
||||||
h.Server.Parent = h
|
|
||||||
err = h.Server.Start()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = h.Server.OpenURL()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// start workflow
|
|
||||||
return h.Start()
|
|
||||||
}
|
|
93
cmd/start.go
Normal file
93
cmd/start.go
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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",
|
||||||
|
RunE: start,
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(startCmd)
|
||||||
|
startCmd.Flags().StringVarP(&startConfig.Path, "path", "p", "", "Project base path")
|
||||||
|
startCmd.Flags().StringVarP(&startConfig.Name, "name", "n", "", "Run a project by its name")
|
||||||
|
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", false, "Enable go install")
|
||||||
|
startCmd.Flags().BoolVarP(&startConfig.Build, "build", "b", false, "Enable go build")
|
||||||
|
startCmd.Flags().BoolVarP(&startConfig.Run, "run", "r", false, "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")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 startConfig.Name != "" {
|
||||||
|
// filter by name flag if exist
|
||||||
|
r.Schema.Projects = r.Schema.Filter("Name", startConfig.Name)
|
||||||
|
}
|
||||||
|
// increase file limit
|
||||||
|
if r.Settings.FileLimit != 0 {
|
||||||
|
if err = r.Settings.Flimit(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// check project list length
|
||||||
|
if len(r.Schema.Projects) == 0 {
|
||||||
|
// create a new project based on given params
|
||||||
|
project := r.Schema.New(startConfig)
|
||||||
|
// Add to projects list
|
||||||
|
r.Schema.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()
|
||||||
|
}
|
@ -7,13 +7,17 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
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: "Prints current verison",
|
Short: "A brief description of your command",
|
||||||
Run: version,
|
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,
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -32,6 +36,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) {
|
||||||
h := haunt.NewHaunt()
|
r := haunt.NewHaunt()
|
||||||
log.Println(h.Prefix(haunt.Green.Bold(Version)))
|
log.Println(r.Prefix(haunt.Green.Bold(haunt.RVersion)))
|
||||||
}
|
}
|
||||||
|
19
go.mod
19
go.mod
@ -3,14 +3,13 @@ module github.com/abs3ntdev/haunt
|
|||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fatih/color v1.17.0
|
github.com/fatih/color v1.14.1
|
||||||
github.com/fsnotify/fsnotify v1.7.0
|
github.com/fsnotify/fsnotify v1.6.0
|
||||||
github.com/labstack/echo v3.3.10+incompatible
|
github.com/labstack/echo v3.3.10+incompatible
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/sirupsen/logrus v1.9.0
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.6.1
|
||||||
golang.org/x/net v0.27.0
|
golang.org/x/net v0.7.0
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@ -18,12 +17,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.20 // indirect
|
github.com/mattn/go-isatty v0.0.17 // 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.25.0 // indirect
|
golang.org/x/crypto v0.6.0 // indirect
|
||||||
golang.org/x/sys v0.22.0 // indirect
|
golang.org/x/sys v0.5.0 // indirect
|
||||||
golang.org/x/text v0.16.0 // indirect
|
golang.org/x/text v0.7.0 // indirect
|
||||||
)
|
)
|
||||||
|
22
go.sum
22
go.sum
@ -1,5 +1,4 @@
|
|||||||
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=
|
||||||
@ -7,12 +6,8 @@ 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=
|
||||||
@ -27,19 +22,13 @@ 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=
|
||||||
@ -57,12 +46,8 @@ 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=
|
||||||
@ -71,15 +56,8 @@ 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=
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
9
main.go
9
main.go
@ -3,14 +3,5 @@ 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()
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["config:recommended"]
|
|
||||||
}
|
|
File diff suppressed because one or more lines are too long
@ -16,14 +16,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// HPrefix tool name
|
// RPrefix tool name
|
||||||
HPrefix = "haunt"
|
RPrefix = "haunt"
|
||||||
// HExt file extension
|
// RVersion current version
|
||||||
HExt = ".yaml"
|
RVersion = "v0.1.3"
|
||||||
// HFile config file name
|
// RExt file extension
|
||||||
HFile = "." + HPrefix + HExt
|
RExt = ".yaml"
|
||||||
// HExtWin windows extension
|
// RFile config file name
|
||||||
HExtWin = ".exe"
|
RFile = "." + RPrefix + RExt
|
||||||
|
// RExtWin windows extension
|
||||||
|
RExtWin = ".exe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@ -76,17 +78,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Haunt) SetDefaults() {
|
func (r *Haunt) SetDefaults() {
|
||||||
h.Server = Server{Parent: h, Status: true, Open: false, Port: Port}
|
r.Server = Server{Parent: r, Status: true, Open: false, Port: Port}
|
||||||
h.Settings.FileLimit = 0
|
r.Settings.FileLimit = 0
|
||||||
h.Settings.Legacy.Interval = 100 * time.Millisecond
|
r.Settings.Legacy.Interval = 100 * time.Millisecond
|
||||||
h.Settings.Legacy.Force = false
|
r.Settings.Legacy.Force = false
|
||||||
h.Settings.Errors = Resource{Name: FileErr, Status: false}
|
r.Settings.Files.Errors = Resource{Name: FileErr, Status: false}
|
||||||
h.Settings.Errors = Resource{Name: FileOut, Status: false}
|
r.Settings.Files.Errors = Resource{Name: FileOut, Status: false}
|
||||||
h.Settings.Errors = Resource{Name: FileLog, Status: false}
|
r.Settings.Files.Errors = Resource{Name: FileLog, Status: false}
|
||||||
if _, err := os.Stat("main.go"); err == nil {
|
if _, err := os.Stat("main.go"); err == nil {
|
||||||
log.Println(h.Prefix(Green.Bold("Adding: " + filepath.Base(Wdir()))))
|
log.Println(r.Prefix(Green.Bold("Adding: " + filepath.Base(Wdir()))))
|
||||||
h.Projects = append(h.Projects, Project{
|
r.Schema.Projects = append(r.Schema.Projects, Project{
|
||||||
Name: filepath.Base(Wdir()),
|
Name: filepath.Base(Wdir()),
|
||||||
Path: Wdir(),
|
Path: Wdir(),
|
||||||
Tools: Tools{
|
Tools: Tools{
|
||||||
@ -99,21 +101,21 @@ func (h *Haunt) SetDefaults() {
|
|||||||
},
|
},
|
||||||
Watcher: Watch{
|
Watcher: Watch{
|
||||||
Exts: []string{"go"},
|
Exts: []string{"go"},
|
||||||
Paths: []string{"./"},
|
Paths: []string{"/"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
log.Println(h.Prefix(Magenta.Bold("Skipping: " + filepath.Base(Wdir()) + " no main.go file in root")))
|
log.Println(r.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(h.Prefix("cmd directory not found, skipping"))
|
log.Println(r.Prefix("cmd directory not found, skipping"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, dir := range subDirs {
|
for _, dir := range subDirs {
|
||||||
if dir.IsDir() {
|
if dir.IsDir() {
|
||||||
log.Println(h.Prefix(Green.Bold("Adding: " + dir.Name())))
|
log.Println(r.Prefix(Green.Bold("Adding: " + dir.Name())))
|
||||||
h.Projects = append(h.Projects, Project{
|
r.Schema.Projects = append(r.Schema.Projects, Project{
|
||||||
Name: dir.Name(),
|
Name: dir.Name(),
|
||||||
Path: "cmd/" + dir.Name(),
|
Path: "cmd/" + dir.Name(),
|
||||||
Tools: Tools{
|
Tools: Tools{
|
||||||
@ -130,31 +132,31 @@ func (h *Haunt) SetDefaults() {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
log.Println(h.Prefix(Magenta.Bold("Skipping: " + dir.Name() + " not a directory")))
|
log.Println(r.Prefix(Magenta.Bold("Skipping: " + dir.Name() + " not a directory")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop haunt workflow
|
// Stop haunt workflow
|
||||||
func (h *Haunt) Stop() error {
|
func (r *Haunt) Stop() error {
|
||||||
for k := range h.Projects {
|
for k := range r.Schema.Projects {
|
||||||
if h.Schema.Projects[k].exit != nil {
|
if r.Schema.Projects[k].exit != nil {
|
||||||
close(h.Schema.Projects[k].exit)
|
close(r.Schema.Projects[k].exit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start haunt workflow
|
// Start haunt workflow
|
||||||
func (h *Haunt) Start() error {
|
func (r *Haunt) Start() error {
|
||||||
if len(h.Projects) > 0 {
|
if len(r.Schema.Projects) > 0 {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(h.Projects))
|
wg.Add(len(r.Schema.Projects))
|
||||||
for k := range h.Projects {
|
for k := range r.Schema.Projects {
|
||||||
h.Schema.Projects[k].exit = make(chan os.Signal, 1)
|
r.Schema.Projects[k].exit = make(chan os.Signal, 1)
|
||||||
signal.Notify(h.Schema.Projects[k].exit, os.Interrupt)
|
signal.Notify(r.Schema.Projects[k].exit, os.Interrupt)
|
||||||
h.Schema.Projects[k].parent = h
|
r.Schema.Projects[k].parent = r
|
||||||
go h.Schema.Projects[k].Watch(&wg)
|
go r.Schema.Projects[k].Watch(&wg)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
} else {
|
} else {
|
||||||
@ -164,9 +166,9 @@ func (h *Haunt) Start() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prefix a given string with tool name
|
// Prefix a given string with tool name
|
||||||
func (h *Haunt) Prefix(input string) string {
|
func (r *Haunt) Prefix(input string) string {
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(HPrefix), Yellow.Bold("]"), ": ", input)
|
return fmt.Sprint(Yellow.Bold("["), strings.ToUpper(RPrefix), Yellow.Bold("]"), ": ", input)
|
||||||
}
|
}
|
||||||
return input
|
return input
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ package haunt
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -116,10 +115,7 @@ func (w *filePoller) Close() error {
|
|||||||
|
|
||||||
w.closed = true
|
w.closed = true
|
||||||
for name := range w.watches {
|
for name := range w.watches {
|
||||||
err := w.remove(name)
|
w.remove(name)
|
||||||
if err != nil {
|
|
||||||
log.Println(log.Prefix(), err.Error())
|
|
||||||
}
|
|
||||||
delete(w.watches, name)
|
delete(w.watches, name)
|
||||||
}
|
}
|
||||||
w.mu.Unlock()
|
w.mu.Unlock()
|
||||||
@ -200,12 +196,7 @@ func (w *filePoller) Walk(path string, init bool) string {
|
|||||||
if check == nil && init {
|
if check == nil && init {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
go func() {
|
go w.sendEvent(fsnotify.Event{Op: fsnotify.Create, Name: path}, w.watches[path])
|
||||||
err := w.sendEvent(fsnotify.Event{Op: fsnotify.Create, Name: path}, w.watches[path])
|
|
||||||
if err != nil {
|
|
||||||
log.Println(log.Prefix(), err.Error())
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return path
|
return path
|
||||||
@ -250,16 +241,13 @@ func (w *filePoller) watch(f *os.File, lastFi os.FileInfo, chClose chan struct{}
|
|||||||
// If it doesn't exist at this point, it must have been removed
|
// If it doesn't exist at this point, it must have been removed
|
||||||
// no need to send the error here since this is a valid operation
|
// no need to send the error here since this is a valid operation
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
if err = w.sendEvent(fsnotify.Event{Op: fsnotify.Remove, Name: f.Name()}, chClose); err != nil {
|
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Remove, Name: f.Name()}, chClose); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lastFi = nil
|
lastFi = nil
|
||||||
}
|
}
|
||||||
// at this point, send the error
|
// at this point, send the error
|
||||||
err = w.sendErr(err, chClose)
|
w.sendErr(err, chClose)
|
||||||
if err != nil {
|
|
||||||
log.Println(log.Prefix(), err.Error())
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
case lastFi == nil:
|
case lastFi == nil:
|
||||||
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Create, Name: f.Name()}, chClose); err != nil {
|
if err := w.sendEvent(fsnotify.Event{Op: fsnotify.Create, Name: f.Name()}, chClose); err != nil {
|
||||||
|
@ -41,12 +41,11 @@ type Ignore struct {
|
|||||||
|
|
||||||
// Command fields
|
// Command fields
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Project info
|
// Project info
|
||||||
@ -116,11 +115,9 @@ func (p *Project) Before() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup go tools
|
// setup go tools
|
||||||
p.Tools.Setup(p)
|
p.Tools.Setup()
|
||||||
|
|
||||||
// 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)
|
||||||
@ -130,7 +127,6 @@ 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"}
|
||||||
@ -143,7 +139,6 @@ 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()}
|
||||||
@ -174,7 +169,6 @@ 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() {
|
||||||
@ -184,17 +178,14 @@ 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)
|
||||||
@ -206,7 +197,6 @@ 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
|
||||||
@ -268,13 +258,6 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
p.stamp("error", out, msg, "")
|
p.stamp("error", out, msg, "")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
} else {
|
|
||||||
if install.Err != nil {
|
|
||||||
log.Println(p.parent.Prefix("Install failed for: " + p.Name))
|
|
||||||
}
|
|
||||||
if build.Err != nil {
|
|
||||||
log.Println(p.parent.Prefix("Build failed for: " + p.Name))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if done {
|
if done {
|
||||||
return
|
return
|
||||||
@ -287,24 +270,19 @@ 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 {
|
||||||
@ -317,10 +295,7 @@ L:
|
|||||||
switch event.Op {
|
switch event.Op {
|
||||||
case fsnotify.Chmod:
|
case fsnotify.Chmod:
|
||||||
case fsnotify.Remove:
|
case fsnotify.Remove:
|
||||||
err := p.watcher.Remove(event.Name)
|
p.watcher.Remove(event.Name)
|
||||||
if err != nil {
|
|
||||||
log.Println(p.parent.Prefix("Failed to remove watcher: " + err.Error()))
|
|
||||||
}
|
|
||||||
if p.Validate(event.Name, false) && ext(event.Name) != "" {
|
if p.Validate(event.Name, false) && ext(event.Name) != "" {
|
||||||
// stop and restart
|
// stop and restart
|
||||||
close(p.stop)
|
close(p.stop)
|
||||||
@ -335,10 +310,7 @@ L:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
err := filepath.Walk(event.Name, p.walk)
|
filepath.Walk(event.Name, p.walk)
|
||||||
if err != nil {
|
|
||||||
log.Println(p.parent.Prefix("Failed to walk directory: " + err.Error()))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// stop and restart
|
// stop and restart
|
||||||
close(p.stop)
|
close(p.stop)
|
||||||
@ -543,7 +515,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.Outputs.Name)
|
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.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, "")
|
||||||
}
|
}
|
||||||
@ -551,7 +523,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.Logs.Name)
|
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.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, "")
|
||||||
}
|
}
|
||||||
@ -559,7 +531,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.Errors.Name)
|
f := p.parent.Settings.Create(p.Path, p.parent.Settings.Files.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, "")
|
||||||
}
|
}
|
||||||
@ -578,14 +550,7 @@ 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.ReplaceAll(k, "=", ""), v))
|
envs = append(envs, fmt.Sprintf("%s=%s", strings.Replace(k, "=", "", -1), 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
|
||||||
}
|
}
|
||||||
@ -599,14 +564,8 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err
|
|||||||
// https://github.com/golang/go/issues/5615
|
// https://github.com/golang/go/issues/5615
|
||||||
// https://github.com/golang/go/issues/6720
|
// https://github.com/golang/go/issues/6720
|
||||||
if build != nil {
|
if build != nil {
|
||||||
err = build.Process.Signal(os.Interrupt)
|
build.Process.Signal(os.Interrupt)
|
||||||
if err != nil {
|
build.Process.Wait()
|
||||||
log.Println(p.parent.Prefix("Failed to send interrupt: " + err.Error()))
|
|
||||||
}
|
|
||||||
_, err = build.Process.Wait()
|
|
||||||
if err != nil {
|
|
||||||
log.Println(p.parent.Prefix("Error: " + err.Error()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -643,15 +602,15 @@ func (p *Project) run(path string, stream chan Response, stop <-chan bool) (err
|
|||||||
if p.Tools.Run.Method != "" {
|
if p.Tools.Run.Method != "" {
|
||||||
path = p.Tools.Run.Method
|
path = p.Tools.Run.Method
|
||||||
}
|
}
|
||||||
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 + HExtWin); err == nil {
|
} else if _, err := os.Stat(path + RExtWin); err == nil {
|
||||||
build = exec.Command(path+HExtWin, args...)
|
build = exec.Command(path+RExtWin, 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 + HExtWin); err == nil {
|
} else if _, err = os.Stat(path + RExtWin); err == nil {
|
||||||
build = exec.Command(path+HExtWin, args...)
|
build = exec.Command(path+RExtWin, args...)
|
||||||
} else {
|
} else {
|
||||||
return errors.New("project not found")
|
return errors.New("project not found")
|
||||||
}
|
}
|
||||||
@ -723,10 +682,6 @@ 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 != "" {
|
||||||
@ -739,19 +694,13 @@ func (c *Command) exec(base string, stop <-chan bool) (response Response) {
|
|||||||
ex.Stdout = &stdout
|
ex.Stdout = &stdout
|
||||||
ex.Stderr = &stderr
|
ex.Stderr = &stderr
|
||||||
// Start command
|
// Start command
|
||||||
err := ex.Start()
|
ex.Start()
|
||||||
if err != nil {
|
|
||||||
log.Println(log.Prefix(), err.Error())
|
|
||||||
}
|
|
||||||
go func() { done <- ex.Wait() }()
|
go func() { done <- ex.Wait() }()
|
||||||
// Wait a result
|
// Wait a result
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
// Stop running command
|
// Stop running command
|
||||||
err := ex.Process.Kill()
|
ex.Process.Kill()
|
||||||
if err != nil {
|
|
||||||
log.Println(log.Prefix(), err.Error())
|
|
||||||
}
|
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
// Command completed
|
// Command completed
|
||||||
response.Name = c.Cmd
|
response.Name = c.Cmd
|
||||||
|
@ -2,8 +2,6 @@ package haunt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/abs3ntdev/haunt/src/config"
|
"github.com/abs3ntdev/haunt/src/config"
|
||||||
@ -37,13 +35,6 @@ 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 = filepath.Base(Wdir())
|
|
||||||
}
|
|
||||||
if flags.Path == "" {
|
|
||||||
flags.Path = Wdir()
|
|
||||||
}
|
|
||||||
fmt.Println(flags.Name)
|
|
||||||
project := Project{
|
project := Project{
|
||||||
Name: flags.Name,
|
Name: flags.Name,
|
||||||
Path: flags.Path,
|
Path: flags.Path,
|
||||||
@ -71,7 +62,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"},
|
||||||
},
|
},
|
||||||
@ -79,13 +70,16 @@ func (s *Schema) New(flags config.Flags) Project {
|
|||||||
return project
|
return project
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter project list by names
|
// Filter project list by field
|
||||||
func (s *Schema) Filter(names []string) []Project {
|
func (s *Schema) Filter(field string, value interface{}) []Project {
|
||||||
result := []Project{}
|
result := []Project{}
|
||||||
for _, item := range s.Projects {
|
for _, item := range s.Projects {
|
||||||
for _, name := range names {
|
v := reflect.ValueOf(item)
|
||||||
if item.Name == name {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
result = append(result, item)
|
if v.Type().Field(i).Name == field {
|
||||||
|
if reflect.DeepEqual(v.Field(i).Interface(), value) {
|
||||||
|
result = append(result, item)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,9 +57,7 @@ func (s *Server) projects(c echo.Context) (err error) {
|
|||||||
} else {
|
} else {
|
||||||
err := json.Unmarshal([]byte(text), &s.Parent)
|
err := json.Unmarshal([]byte(text), &s.Parent)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := s.Parent.Settings.Write(s.Parent); err != nil {
|
s.Parent.Settings.Write(s.Parent)
|
||||||
log.Println(s.Parent.Prefix("Failed to write: " + err.Error()))
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,10 +88,7 @@ func (s *Server) render(c echo.Context, path string, mime int) error {
|
|||||||
rs.Header().Set(echo.HeaderContentType, "image/png")
|
rs.Header().Set(echo.HeaderContentType, "image/png")
|
||||||
}
|
}
|
||||||
rs.WriteHeader(http.StatusOK)
|
rs.WriteHeader(http.StatusOK)
|
||||||
_, err = rs.Write(data)
|
rs.Write(data)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,11 +151,8 @@ func (s *Server) Start() (err error) {
|
|||||||
e.HideBanner = true
|
e.HideBanner = true
|
||||||
e.Debug = false
|
e.Debug = false
|
||||||
go func() {
|
go func() {
|
||||||
err := e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port))
|
|
||||||
if err != nil {
|
|
||||||
log.Println(s.Parent.Prefix("Failed to start on " + s.Host + ":" + strconv.Itoa(s.Port)))
|
|
||||||
}
|
|
||||||
log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port)))
|
log.Println(s.Parent.Prefix("Started on " + string(s.Host) + ":" + strconv.Itoa(s.Port)))
|
||||||
|
e.Start(string(s.Host) + ":" + strconv.Itoa(s.Port))
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package haunt
|
package haunt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -13,9 +14,9 @@ import (
|
|||||||
const (
|
const (
|
||||||
Permission = 0o775
|
Permission = 0o775
|
||||||
File = ".haunt.yaml"
|
File = ".haunt.yaml"
|
||||||
FileOut = ".h.outputs.log"
|
FileOut = ".r.outputs.log"
|
||||||
FileErr = ".h.errors.log"
|
FileErr = ".r.errors.log"
|
||||||
FileLog = ".h.logs.log"
|
FileLog = ".r.logs.log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings defines a group of general settings and options
|
// Settings defines a group of general settings and options
|
||||||
@ -71,10 +72,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(HFile); err != nil {
|
if _, err := os.Stat(RFile); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
content, err := s.Stream(HFile)
|
content, err := s.Stream(RFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = yaml.Unmarshal(content, out)
|
err = yaml.Unmarshal(content, out)
|
||||||
return err
|
return err
|
||||||
@ -88,7 +89,7 @@ func (s *Settings) Write(out interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.Fatal(os.WriteFile(HFile, y, Permission))
|
s.Fatal(ioutil.WriteFile(RFile, y, Permission))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ func (s Settings) Stream(file string) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
content, err := os.ReadFile(file)
|
content, err := ioutil.ReadFile(file)
|
||||||
s.Fatal(err)
|
s.Fatal(err)
|
||||||
return content, err
|
return content, err
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -39,7 +39,7 @@ type Tools struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup go tools
|
// Setup go tools
|
||||||
func (t *Tools) Setup(p *Project) {
|
func (t *Tools) Setup() {
|
||||||
gocmd := "go"
|
gocmd := "go"
|
||||||
|
|
||||||
// go clean
|
// go clean
|
||||||
@ -48,8 +48,6 @@ func (t *Tools) Setup(p *Project) {
|
|||||||
t.Clean.isTool = true
|
t.Clean.isTool = true
|
||||||
t.Clean.cmd = replace([]string{gocmd, "clean"}, t.Clean.Method)
|
t.Clean.cmd = replace([]string{gocmd, "clean"}, t.Clean.Method)
|
||||||
t.Clean.Args = split([]string{}, t.Clean.Args)
|
t.Clean.Args = split([]string{}, t.Clean.Args)
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Magenta.Bold(t.Clean.name), "running. Method:", Blue.Bold(strings.Join(t.Clean.cmd, " "), " ", strings.Join(t.Clean.Args, " ")))
|
|
||||||
log.Print(msg)
|
|
||||||
}
|
}
|
||||||
// go generate
|
// go generate
|
||||||
if t.Generate.Status {
|
if t.Generate.Status {
|
||||||
@ -58,8 +56,6 @@ func (t *Tools) Setup(p *Project) {
|
|||||||
t.Generate.name = "Generate"
|
t.Generate.name = "Generate"
|
||||||
t.Generate.cmd = replace([]string{gocmd, "generate"}, t.Generate.Method)
|
t.Generate.cmd = replace([]string{gocmd, "generate"}, t.Generate.Method)
|
||||||
t.Generate.Args = split([]string{}, t.Generate.Args)
|
t.Generate.Args = split([]string{}, t.Generate.Args)
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Magenta.Bold(t.Generate.name), "running. Method:", Blue.Bold(strings.Join(t.Generate.cmd, " "), " ", strings.Join(t.Generate.Args, " ")))
|
|
||||||
log.Print(msg)
|
|
||||||
}
|
}
|
||||||
// go fmt
|
// go fmt
|
||||||
if t.Fmt.Status {
|
if t.Fmt.Status {
|
||||||
@ -70,8 +66,6 @@ func (t *Tools) Setup(p *Project) {
|
|||||||
t.Fmt.isTool = true
|
t.Fmt.isTool = true
|
||||||
t.Fmt.cmd = replace([]string{"gofmt"}, t.Fmt.Method)
|
t.Fmt.cmd = replace([]string{"gofmt"}, t.Fmt.Method)
|
||||||
t.Fmt.Args = split([]string{}, t.Fmt.Args)
|
t.Fmt.Args = split([]string{}, t.Fmt.Args)
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Magenta.Bold(t.Fmt.name), "running. Method:", Blue.Bold(strings.Join(t.Fmt.cmd, " "), " ", strings.Join(t.Fmt.Args, " ")))
|
|
||||||
log.Print(msg)
|
|
||||||
}
|
}
|
||||||
// go vet
|
// go vet
|
||||||
if t.Vet.Status {
|
if t.Vet.Status {
|
||||||
@ -80,8 +74,6 @@ func (t *Tools) Setup(p *Project) {
|
|||||||
t.Vet.isTool = true
|
t.Vet.isTool = true
|
||||||
t.Vet.cmd = replace([]string{gocmd, "vet"}, t.Vet.Method)
|
t.Vet.cmd = replace([]string{gocmd, "vet"}, t.Vet.Method)
|
||||||
t.Vet.Args = split([]string{}, t.Vet.Args)
|
t.Vet.Args = split([]string{}, t.Vet.Args)
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Magenta.Bold(t.Vet.name), "running. Method:", Blue.Bold(strings.Join(t.Vet.cmd, " "), " ", strings.Join(t.Vet.Args, " ")))
|
|
||||||
log.Print(msg)
|
|
||||||
}
|
}
|
||||||
// go test
|
// go test
|
||||||
if t.Test.Status {
|
if t.Test.Status {
|
||||||
@ -90,13 +82,11 @@ func (t *Tools) Setup(p *Project) {
|
|||||||
t.Test.name = "Test"
|
t.Test.name = "Test"
|
||||||
t.Test.cmd = replace([]string{gocmd, "test"}, t.Test.Method)
|
t.Test.cmd = replace([]string{gocmd, "test"}, t.Test.Method)
|
||||||
t.Test.Args = split([]string{}, t.Test.Args)
|
t.Test.Args = split([]string{}, t.Test.Args)
|
||||||
p.parent.Prefix(t.Test.name + ": Running")
|
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", Magenta.Bold(t.Test.name), "running. Method:", Blue.Bold(strings.Join(t.Test.cmd, " "), " ", strings.Join(t.Test.Args, " ")))
|
|
||||||
log.Print(msg)
|
|
||||||
}
|
}
|
||||||
// go install
|
// go install
|
||||||
t.Install.name = "Install"
|
t.Install.name = "Install"
|
||||||
t.Install.cmd = replace([]string{gocmd, "install"}, t.Install.Method)
|
t.Install.cmd = replace([]string{gocmd, "install"}, t.Install.Method)
|
||||||
|
fmt.Println(t.Install.cmd)
|
||||||
t.Install.Args = split([]string{}, t.Install.Args)
|
t.Install.Args = split([]string{}, t.Install.Args)
|
||||||
// go build
|
// go build
|
||||||
if t.Build.Status {
|
if t.Build.Status {
|
||||||
@ -114,7 +104,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
|
|||||||
}
|
}
|
||||||
// check if there is at least one go file
|
// check if there is at least one go file
|
||||||
matched := false
|
matched := false
|
||||||
files, _ := os.ReadDir(path)
|
files, _ := ioutil.ReadDir(path)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
matched, _ = filepath.Match("*.go", f.Name())
|
matched, _ = filepath.Match("*.go", f.Name())
|
||||||
if matched {
|
if matched {
|
||||||
@ -147,7 +137,6 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
|
|||||||
}
|
}
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
// Start command
|
// Start command
|
||||||
err := cmd.Start()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -160,9 +149,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
|
|||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
// Stop running command
|
// Stop running command
|
||||||
if err := cmd.Process.Kill(); err != nil {
|
cmd.Process.Kill()
|
||||||
response.Err = err
|
|
||||||
}
|
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
// Command completed
|
// Command completed
|
||||||
response.Name = t.name
|
response.Name = t.name
|
||||||
@ -193,29 +180,14 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
|
|||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
cmd.Stderr = &stderr
|
cmd.Stderr = &stderr
|
||||||
// Start command
|
// Start command
|
||||||
err := cmd.Start()
|
cmd.Start()
|
||||||
if err != nil {
|
go func() { done <- cmd.Wait() }()
|
||||||
log.Println(log.Prefix(), err.Error())
|
|
||||||
if cmd.Process != nil {
|
|
||||||
err := cmd.Process.Kill()
|
|
||||||
if err != nil {
|
|
||||||
log.Println(log.Prefix(), err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
done <- cmd.Wait()
|
|
||||||
}()
|
|
||||||
// Wait a result
|
// Wait a result
|
||||||
response.Name = t.name
|
response.Name = t.name
|
||||||
select {
|
select {
|
||||||
case <-stop:
|
case <-stop:
|
||||||
// Stop running command
|
// Stop running command
|
||||||
err := cmd.Process.Kill()
|
cmd.Process.Kill()
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case err := <-done:
|
case err := <-done:
|
||||||
// Command completed
|
// Command completed
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user