Compare commits

...

19 Commits

Author SHA1 Message Date
abs3nt 8cf145955c
docs: version bump
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-03-11 21:35:03 -08:00
abs3nt 62c1714958
updates
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-03-10 09:59:19 -08:00
abs3nt 49effe24b4
update urls 2023-03-09 23:48:25 -08:00
abs3nt 0f19f085ff
docs: version bump
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-03-08 15:16:52 -08:00
abs3nt 7fa2e67a89
docs: readme
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-08 15:16:39 -08:00
abs3nt 0a0c88f25d
feat: per script environmental variables
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-08 15:14:45 -08:00
abs3nt 4992e63edb
docs: version bump
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-08 13:47:07 -08:00
abs3nt 32d1074fd9
improved: aliases
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-08 13:46:44 -08:00
abs3nt 8f9ff1dada
docs: readme
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-08 13:22:04 -08:00
abs3nt ec35355705
docs: readme
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-08 13:07:06 -08:00
abs3nt 40203011d5 fix: fix makefile
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-06 17:49:03 -08:00
abs3nt 2d893b57c2 doc: version bump
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-03-06 11:02:52 -08:00
abs3nt 4e854075df improved: make haunt run generate default config if none found
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-06 11:02:34 -08:00
abs3nt 0e454d971d ci: add site unpacking / packing to makefile, ignore assets directory
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-06 10:39:51 -08:00
abs3nt 764265ba04 docs: version bump
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-03-06 10:18:00 -08:00
abs3nt 8dd9007194 remove
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-03-06 10:17:39 -08:00
abs3nt ee43417bb5 server redo 2023-03-06 10:17:28 -08:00
abs3nt 8805406e51 version bump
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-03-05 23:58:07 -08:00
abs3nt 55e3fe4fca fix: remove debug
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
2023-03-05 23:57:48 -08:00
16 changed files with 268 additions and 100 deletions

1
.gitignore vendored
View File

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

View File

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

View File

@ -5,6 +5,12 @@ ${pkgname}: $(shell find . -name '*.go')
mkdir -p bin
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:
mkdir -p completions
./bin/${pkgname} completion zsh > completions/_${pkgname}
@ -18,17 +24,18 @@ tidy:
go mod tidy
clean:
rm -f bin
rm -rf bin
rm -rf completions
rm -rf assets
uninstall:
rm -f /usr/bin/${pkgname}
rm -f /usr/local/bin/${pkgname}
rm -f /usr/share/zsh/site-functions/_${pkgname}
rm -f /usr/share/bash-completion/completions/${pkgname}
rm -f /usr/share/fish/vendor_completions.d/${pkgname}.fish
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 bash > /usr/share/bash-completion/completions/${pkgname}
bin/${pkgname} completion fish > /usr/share/fish/vendor_completions.d/${pkgname}.fish

View File

@ -12,6 +12,12 @@ cd haunt
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]`
@ -59,6 +65,7 @@ Possible flags are:
-t, --test Enable go test
-v, --vet Enable go vet
### Remove Command
Remove a project by its name
@ -83,7 +90,7 @@ Remove a project by its name
schema:
- name: coin
path: cmd/coin // project path
env: // env variables available at startup
env: // env variables for run
test: test
myvar: value
commands: // go commands supported
@ -124,12 +131,20 @@ Remove a project by its name
command: echo before global
global: true
output: true
env: // env variables per script
test: test
myvar: value
- type: before
command: echo before change
output: true
env: // env variables per script
test: othertest
myvar: othervalue
- type: after
command: echo after change
output: true
env: // env variables per script
key: 1
- type: after
command: echo after global
global: true

View File

@ -13,10 +13,11 @@ import (
var addConfig config.Flags
var addCmd = &cobra.Command{
Use: "add",
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",
Args: cobra.MatchAll(cobra.ExactArgs(1)),
Use: "add",
Aliases: []string{"a", "create", "new"},
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",
Args: cobra.MatchAll(cobra.ExactArgs(1)),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) >= 1 {
return nil, cobra.ShellCompDirectiveNoFileComp

View File

@ -9,9 +9,10 @@ import (
// cleanCmd represents the clean command
var cleanCmd = &cobra.Command{
Use: "clean",
Short: "Deletes the haunt config file",
RunE: clean,
Use: "clean",
Aliases: []string{"c"},
Short: "Deletes the haunt config file",
RunE: clean,
}
func init() {

View File

@ -12,10 +12,11 @@ import (
// initCmd represents the init command
var initCmd = &cobra.Command{
Use: "init",
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",
RunE: defaultConfig,
Use: "init",
Aliases: []string{"i"},
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",
RunE: defaultConfig,
}
func init() {

View File

@ -9,9 +9,10 @@ import (
)
var removeCmd = &cobra.Command{
Use: "remove [names]",
Short: "Removes all projects by name from config file",
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
Use: "remove [names]",
Aliases: []string{"delete", "r"},
Short: "Removes all projects by name from config file",
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return getProjectNames(toComplete), cobra.ShellCompDirectiveNoFileComp
},

View File

@ -1,25 +1,28 @@
package cmd
import (
"fmt"
"log"
"os"
"strings"
"github.com/abs3ntdev/haunt/src/haunt"
"github.com/spf13/cobra"
)
var runCmd = &cobra.Command{
Use: "run",
Short: "run haunt, optionally provide the name of projects to only run those otherwise will run all configured projects",
Args: cobra.MatchAll(cobra.OnlyValidArgs),
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: run,
RunE: start,
}
func init() {
rootCmd.AddCommand(runCmd)
rootCmd.AddCommand(startCmd)
}
func getProjectNamesToRun(input string) []string {
@ -39,13 +42,25 @@ func getProjectNamesToRun(input string) []string {
}
// haunt workflow
func run(cmd *cobra.Command, args []string) (err error) {
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 {
return err
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
@ -75,6 +90,6 @@ func run(cmd *cobra.Command, args []string) (err error) {
}
}
// run workflow
return h.Run()
// start workflow
return h.Start()
}

View File

@ -7,19 +7,13 @@ import (
"github.com/spf13/cobra"
)
var Version = "v0.2.2"
var Version = "v0.2.11"
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "A brief description of your command",
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,
Short: "Prints current verison",
Run: version,
}
func init() {

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"
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()
}

File diff suppressed because one or more lines are too long

View File

@ -145,8 +145,8 @@ func (h *Haunt) Stop() error {
return nil
}
// Run haunt workflow
func (h *Haunt) Run() error {
// Start haunt workflow
func (h *Haunt) Start() error {
if len(h.Projects) > 0 {
var wg sync.WaitGroup
wg.Add(len(h.Projects))

View File

@ -41,11 +41,12 @@ type Ignore struct {
// Command fields
type Command struct {
Cmd string `yaml:"command" json:"command"`
Type string `yaml:"type" json:"type"`
Path string `yaml:"path,omitempty" json:"path,omitempty"`
Global bool `yaml:"global,omitempty" json:"global,omitempty"`
Output bool `yaml:"output,omitempty" json:"output,omitempty"`
Cmd string `yaml:"command" json:"command"`
Type string `yaml:"type" json:"type"`
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Path string `yaml:"path,omitempty" json:"path,omitempty"`
Global bool `yaml:"global,omitempty" json:"global,omitempty"`
Output bool `yaml:"output,omitempty" json:"output,omitempty"`
}
// Project info
@ -542,7 +543,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
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 {
p.parent.Settings.Fatal(err, "")
}
@ -550,7 +551,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
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 {
p.parent.Settings.Fatal(err, "")
}
@ -558,7 +559,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
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 {
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) {
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
}
@ -715,6 +723,10 @@ func (c *Command) exec(base string, stop <-chan bool) (response Response) {
done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(c.Cmd, "'", "", -1), "\"", "", -1), " ")
ex := exec.Command(args[0], args[1:]...)
appendEnvs := c.buildEnvs()
if len(appendEnvs) > 0 {
ex.Env = append(ex.Env, appendEnvs...)
}
ex.Dir = base
// make cmd path
if c.Path != "" {

View File

@ -185,7 +185,6 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
done := make(chan error)
args := append(t.cmd, t.Args...)
cmd := exec.Command(args[0], args[1:]...)
fmt.Println(cmd)
if t.Dir != "" {
cmd.Dir, _ = filepath.Abs(t.Dir)
} else {