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

@ -13,10 +13,11 @@ import (
var addConfig config.Flags var addConfig config.Flags
var addCmd = &cobra.Command{ var addCmd = &cobra.Command{
Use: "add", Use: "add",
Short: "Adds a project by name", Aliases: []string{"a", "create", "new"},
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", Short: "Adds a project by name",
Args: cobra.MatchAll(cobra.ExactArgs(1)), 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) { 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

View File

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

View File

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

View File

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

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",
Short: "run haunt, optionally provide the name of projects to only run those otherwise will run all configured projects", Aliases: []string{"s", "run"},
Args: cobra.MatchAll(cobra.OnlyValidArgs), 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) { 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))