improved: aliases
ci/woodpecker/push/woodpecker Pipeline was successful Details

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 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

@ -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))