Skip to content

Commit

Permalink
style: delete all unused cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehunter9 committed Feb 26, 2025
1 parent 6f198a1 commit 235c568
Show file tree
Hide file tree
Showing 26 changed files with 1,362 additions and 1,563 deletions.
42 changes: 18 additions & 24 deletions packages/backend/cmd/cmds.go
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)
// }
// }
//}
44 changes: 19 additions & 25 deletions packages/backend/cmd/cmds_add.go
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{}),
//}
54 changes: 25 additions & 29 deletions packages/backend/cmd/cmds_ls.go
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{}),
//}
102 changes: 48 additions & 54 deletions packages/backend/cmd/cmds_rm.go
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{}),
//}
Loading

0 comments on commit 235c568

Please sign in to comment.