Compare commits
22 Commits
Author | SHA1 | Date |
---|---|---|
abs3nt | 8cf145955c | |
abs3nt | 62c1714958 | |
abs3nt | 49effe24b4 | |
abs3nt | 0f19f085ff | |
abs3nt | 7fa2e67a89 | |
abs3nt | 0a0c88f25d | |
abs3nt | 4992e63edb | |
abs3nt | 32d1074fd9 | |
abs3nt | 8f9ff1dada | |
abs3nt | ec35355705 | |
abs3nt | 40203011d5 | |
abs3nt | 2d893b57c2 | |
abs3nt | 4e854075df | |
abs3nt | 0e454d971d | |
abs3nt | 764265ba04 | |
abs3nt | 8dd9007194 | |
abs3nt | ee43417bb5 | |
abs3nt | 8805406e51 | |
abs3nt | 55e3fe4fca | |
abs3nt | d7c1169e39 | |
abs3nt | b06ee1d6d7 | |
abs3nt | f0c93b4fde |
|
@ -25,6 +25,7 @@ _testmain.go
|
|||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
/assets/
|
||||
|
||||
.glide
|
||||
.idea
|
||||
|
|
|
@ -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:
|
||||
|
|
13
Makefile
13
Makefile
|
@ -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
|
||||
|
|
26
README.md
26
README.md
|
@ -1,4 +1,5 @@
|
|||
## Quickstart
|
||||
### Install
|
||||
```
|
||||
go install github.com/abs3ntdev/haunt@latest
|
||||
```
|
||||
|
@ -11,6 +12,20 @@ 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]`
|
||||
|
||||
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
|
||||
|
||||
### Init Command
|
||||
|
@ -50,6 +65,7 @@ Possible flags are:
|
|||
-t, --test Enable go test
|
||||
-v, --vet Enable go vet
|
||||
|
||||
|
||||
### Remove Command
|
||||
Remove a project by its name
|
||||
|
||||
|
@ -74,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
|
||||
|
@ -115,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
35
cmd/run.go
35
cmd/run.go
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -7,19 +7,13 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "v0.2.1"
|
||||
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() {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
9
main.go
9
main.go
|
@ -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
|
@ -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))
|
||||
|
|
|
@ -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 != "" {
|
||||
|
|
|
@ -183,14 +183,8 @@ func (t *Tool) Compile(path string, stop <-chan bool) (response Response) {
|
|||
var out bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
done := make(chan error)
|
||||
buildPath, _ := filepath.Abs(Wdir())
|
||||
buildPath = "-o " + buildPath
|
||||
buildPath += "/bin"
|
||||
fmt.Println(t.cmd, t.Args)
|
||||
args := append(t.cmd, buildPath)
|
||||
args = append(args, t.Args...)
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue