improved: aliases
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
abs3nt 2023-03-08 13:46:44 -08:00
parent 8f9ff1dada
commit 32d1074fd9
Signed by: abs3nt
GPG Key ID: FDC6662313FA9386
6 changed files with 30 additions and 25 deletions

View File

@ -14,6 +14,7 @@ var addConfig config.Flags
var addCmd = &cobra.Command{ var addCmd = &cobra.Command{
Use: "add", Use: "add",
Aliases: []string{"a", "create", "new"},
Short: "Adds a project by name", Short: "Adds a project by name",
Long: "Adds a project by name, if path is provided it will use 'cmd/name', all flags provided will be saved in the config file. By default go install and go run will be ran", Long: "Adds a project by name, if path is provided it will use 'cmd/name', all flags provided will be saved in the config file. By default go install and go run will be ran",
Args: cobra.MatchAll(cobra.ExactArgs(1)), Args: cobra.MatchAll(cobra.ExactArgs(1)),

View File

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

View File

@ -13,6 +13,7 @@ import (
// initCmd represents the init command // initCmd represents the init command
var initCmd = &cobra.Command{ var initCmd = &cobra.Command{
Use: "init", Use: "init",
Aliases: []string{"i"},
Short: "Generates a haunt config file using sane defaults", Short: "Generates a haunt config file using sane defaults",
Long: "Generates a haunt config file using sane defaults, haunt will look for a main.go file and any directories inside the relative path 'cmd' and add them all as projects", Long: "Generates a haunt config file using sane defaults, haunt will look for a main.go file and any directories inside the relative path 'cmd' and add them all as projects",
RunE: defaultConfig, RunE: defaultConfig,

View File

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

View File

@ -10,18 +10,19 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var runCmd = &cobra.Command{ var startCmd = &cobra.Command{
Use: "run", Use: "start",
Aliases: []string{"s", "run"},
Short: "run haunt, optionally provide the name of projects to only run those otherwise will run all configured projects", Short: "run haunt, optionally provide the name of projects to only run those otherwise will run all configured projects",
Args: cobra.MatchAll(cobra.OnlyValidArgs), Args: cobra.MatchAll(cobra.OnlyValidArgs),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return getProjectNamesToRun(toComplete), cobra.ShellCompDirectiveNoFileComp return getProjectNamesToRun(toComplete), cobra.ShellCompDirectiveNoFileComp
}, },
RunE: run, RunE: start,
} }
func init() { func init() {
rootCmd.AddCommand(runCmd) rootCmd.AddCommand(startCmd)
} }
func getProjectNamesToRun(input string) []string { func getProjectNamesToRun(input string) []string {
@ -41,7 +42,7 @@ func getProjectNamesToRun(input string) []string {
} }
// haunt workflow // haunt workflow
func run(cmd *cobra.Command, args []string) (err error) { func start(cmd *cobra.Command, args []string) (err error) {
h := haunt.NewHaunt() h := haunt.NewHaunt()
// read a config if exist // read a config if exist
@ -89,6 +90,6 @@ func run(cmd *cobra.Command, args []string) (err error) {
} }
} }
// run workflow // start workflow
return h.Run() return h.Start()
} }

View File

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