added some extra commands
All checks were successful
Go / build-test-publish (1.23.4) (push) Successful in 43s

This commit is contained in:
Denys Seredenko
2025-01-14 16:27:50 +01:00
parent c2d06f2b7f
commit ca2d6bbc67
4 changed files with 125 additions and 0 deletions

47
cmd/delete/delete.go Normal file
View File

@@ -0,0 +1,47 @@
package delete
import (
"errors"
"git.denysoft.de/CubeBit/ssh-hub/util"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
)
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete alias and it's command",
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
return err
}
conf := viper.GetStringMapString("data")
if _, ok := conf[args[0]]; !ok {
return errors.New("such alias doesn't exist")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
cfg := viper.GetStringMapString("data")
delete(cfg, args[0])
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 deleteCmd
}