Compare commits

...

11 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
11 changed files with 75 additions and 49 deletions

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

@ -6,7 +6,7 @@ ${pkgname}: $(shell find . -name '*.go')
go build -o bin/${pkgname} .
decode:
go run hack/unpack/main.go
go run ./hack/unpack/main.go
pack-site:
go-bindata -pkg haunt -o src/haunt/bindata.go -fs assets/...
@ -29,13 +29,13 @@ clean:
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

@ -10,18 +10,19 @@ import (
"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 {
@ -41,7 +42,7 @@ 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
@ -89,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.6"
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() {

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 != "" {