-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f198a1
commit 235c568
Showing
26 changed files
with
1,362 additions
and
1,563 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(cmdsCmd) | ||
} | ||
|
||
var cmdsCmd = &cobra.Command{ | ||
Use: "cmds", | ||
Short: "Command runner management utility", | ||
Long: `Command runner management utility.`, | ||
Args: cobra.NoArgs, | ||
} | ||
|
||
func printEvents(m map[string][]string) { | ||
for evt, cmds := range m { | ||
for i, cmd := range cmds { | ||
fmt.Printf("%s(%d): %s\n", evt, i, cmd) | ||
} | ||
} | ||
} | ||
//func init() { | ||
// rootCmd.AddCommand(cmdsCmd) | ||
//} | ||
// | ||
//var cmdsCmd = &cobra.Command{ | ||
// Use: "cmds", | ||
// Short: "Command runner management utility", | ||
// Long: `Command runner management utility.`, | ||
// Args: cobra.NoArgs, | ||
//} | ||
// | ||
//func printEvents(m map[string][]string) { | ||
// for evt, cmds := range m { | ||
// for i, cmd := range cmds { | ||
// fmt.Printf("%s(%d): %s\n", evt, i, cmd) | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
cmdsCmd.AddCommand(cmdsAddCmd) | ||
} | ||
|
||
var cmdsAddCmd = &cobra.Command{ | ||
Use: "add <event> <command>", | ||
Short: "Add a command to run on a specific event", | ||
Long: `Add a command to run on a specific event.`, | ||
Args: cobra.MinimumNArgs(2), //nolint:gomnd | ||
Run: python(func(cmd *cobra.Command, args []string, d pythonData) { | ||
s, err := d.store.Settings.Get() | ||
checkErr(err) | ||
command := strings.Join(args[1:], " ") | ||
s.Commands[args[0]] = append(s.Commands[args[0]], command) | ||
err = d.store.Settings.Save(s) | ||
checkErr(err) | ||
printEvents(s.Commands) | ||
}, pythonConfig{}), | ||
} | ||
//func init() { | ||
// cmdsCmd.AddCommand(cmdsAddCmd) | ||
//} | ||
// | ||
//var cmdsAddCmd = &cobra.Command{ | ||
// Use: "add <event> <command>", | ||
// Short: "Add a command to run on a specific event", | ||
// Long: `Add a command to run on a specific event.`, | ||
// Args: cobra.MinimumNArgs(2), //nolint:gomnd | ||
// Run: python(func(cmd *cobra.Command, args []string, d pythonData) { | ||
// s, err := d.store.Settings.Get() | ||
// checkErr(err) | ||
// command := strings.Join(args[1:], " ") | ||
// s.Commands[args[0]] = append(s.Commands[args[0]], command) | ||
// err = d.store.Settings.Save(s) | ||
// checkErr(err) | ||
// printEvents(s.Commands) | ||
// }, pythonConfig{}), | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
cmdsCmd.AddCommand(cmdsLsCmd) | ||
cmdsLsCmd.Flags().StringP("event", "e", "", "event name, without 'before' or 'after'") | ||
} | ||
|
||
var cmdsLsCmd = &cobra.Command{ | ||
Use: "ls", | ||
Short: "List all commands for each event", | ||
Long: `List all commands for each event.`, | ||
Args: cobra.NoArgs, | ||
Run: python(func(cmd *cobra.Command, args []string, d pythonData) { | ||
s, err := d.store.Settings.Get() | ||
checkErr(err) | ||
evt := mustGetString(cmd.Flags(), "event") | ||
|
||
if evt == "" { | ||
printEvents(s.Commands) | ||
} else { | ||
show := map[string][]string{} | ||
show["before_"+evt] = s.Commands["before_"+evt] | ||
show["after_"+evt] = s.Commands["after_"+evt] | ||
printEvents(show) | ||
} | ||
}, pythonConfig{}), | ||
} | ||
//func init() { | ||
// cmdsCmd.AddCommand(cmdsLsCmd) | ||
// cmdsLsCmd.Flags().StringP("event", "e", "", "event name, without 'before' or 'after'") | ||
//} | ||
// | ||
//var cmdsLsCmd = &cobra.Command{ | ||
// Use: "ls", | ||
// Short: "List all commands for each event", | ||
// Long: `List all commands for each event.`, | ||
// Args: cobra.NoArgs, | ||
// Run: python(func(cmd *cobra.Command, args []string, d pythonData) { | ||
// s, err := d.store.Settings.Get() | ||
// checkErr(err) | ||
// evt := mustGetString(cmd.Flags(), "event") | ||
// | ||
// if evt == "" { | ||
// printEvents(s.Commands) | ||
// } else { | ||
// show := map[string][]string{} | ||
// show["before_"+evt] = s.Commands["before_"+evt] | ||
// show["after_"+evt] = s.Commands["after_"+evt] | ||
// printEvents(show) | ||
// } | ||
// }, pythonConfig{}), | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
cmdsCmd.AddCommand(cmdsRmCmd) | ||
} | ||
|
||
var cmdsRmCmd = &cobra.Command{ | ||
Use: "rm <event> <index> [index_end]", | ||
Short: "Removes a command from an event hooker", | ||
Long: `Removes a command from an event hooker. The provided index | ||
is the same that's printed when you run 'cmds ls'. Note | ||
that after each removal/addition, the index of the | ||
commands change. So be careful when removing them after each | ||
other. | ||
You can also specify an optional parameter (index_end) so | ||
you can remove all commands from 'index' to 'index_end', | ||
including 'index_end'.`, | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
if err := cobra.RangeArgs(2, 3)(cmd, args); err != nil { //nolint:gomnd | ||
return err | ||
} | ||
|
||
for _, arg := range args[1:] { | ||
if _, err := strconv.Atoi(arg); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
Run: python(func(cmd *cobra.Command, args []string, d pythonData) { | ||
s, err := d.store.Settings.Get() | ||
checkErr(err) | ||
evt := args[0] | ||
|
||
i, err := strconv.Atoi(args[1]) | ||
checkErr(err) | ||
f := i | ||
if len(args) == 3 { //nolint:gomnd | ||
f, err = strconv.Atoi(args[2]) | ||
checkErr(err) | ||
} | ||
|
||
s.Commands[evt] = append(s.Commands[evt][:i], s.Commands[evt][f+1:]...) | ||
err = d.store.Settings.Save(s) | ||
checkErr(err) | ||
printEvents(s.Commands) | ||
}, pythonConfig{}), | ||
} | ||
//func init() { | ||
// cmdsCmd.AddCommand(cmdsRmCmd) | ||
//} | ||
// | ||
//var cmdsRmCmd = &cobra.Command{ | ||
// Use: "rm <event> <index> [index_end]", | ||
// Short: "Removes a command from an event hooker", | ||
// Long: `Removes a command from an event hooker. The provided index | ||
//is the same that's printed when you run 'cmds ls'. Note | ||
//that after each removal/addition, the index of the | ||
//commands change. So be careful when removing them after each | ||
//other. | ||
// | ||
//You can also specify an optional parameter (index_end) so | ||
//you can remove all commands from 'index' to 'index_end', | ||
//including 'index_end'.`, | ||
// Args: func(cmd *cobra.Command, args []string) error { | ||
// if err := cobra.RangeArgs(2, 3)(cmd, args); err != nil { //nolint:gomnd | ||
// return err | ||
// } | ||
// | ||
// for _, arg := range args[1:] { | ||
// if _, err := strconv.Atoi(arg); err != nil { | ||
// return err | ||
// } | ||
// } | ||
// | ||
// return nil | ||
// }, | ||
// Run: python(func(cmd *cobra.Command, args []string, d pythonData) { | ||
// s, err := d.store.Settings.Get() | ||
// checkErr(err) | ||
// evt := args[0] | ||
// | ||
// i, err := strconv.Atoi(args[1]) | ||
// checkErr(err) | ||
// f := i | ||
// if len(args) == 3 { //nolint:gomnd | ||
// f, err = strconv.Atoi(args[2]) | ||
// checkErr(err) | ||
// } | ||
// | ||
// s.Commands[evt] = append(s.Commands[evt][:i], s.Commands[evt][f+1:]...) | ||
// err = d.store.Settings.Save(s) | ||
// checkErr(err) | ||
// printEvents(s.Commands) | ||
// }, pythonConfig{}), | ||
//} |
Oops, something went wrong.