All checks were successful
Build and Test / build-test (1.23.4) (push) Successful in 1m37s
* autocompletion for exec
45 lines
940 B
Go
45 lines
940 B
Go
package replace
|
|
|
|
import (
|
|
"git.denysoft.de/CubeBit/ssh-hub/util"
|
|
"github.com/jedib0t/go-pretty/v6/table"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
var replaceCmd = &cobra.Command{
|
|
Use: "replace",
|
|
Short: "Replace string with new string in all commands",
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
if err := cobra.ExactArgs(2)(cmd, args); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
},
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
cfg := viper.GetStringMapString("data")
|
|
|
|
for alias, command := range cfg {
|
|
cfg[alias] = strings.Replace(command, args[0], args[1], -1)
|
|
}
|
|
|
|
err := util.SaveConfig(&cfg)
|
|
cobra.CheckErr(err)
|
|
|
|
t := table.NewWriter()
|
|
t.SetOutputMirror(os.Stdout)
|
|
t.AppendHeader(table.Row{"Alias", "Command"})
|
|
|
|
for alias, command := range cfg {
|
|
t.AppendRow(table.Row{alias, command})
|
|
}
|
|
t.Render()
|
|
},
|
|
}
|
|
|
|
func Cmd() *cobra.Command {
|
|
return replaceCmd
|
|
}
|