2020-08-06 20:58:47 +03:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2021-02-22 10:37:00 +03:00
|
|
|
func newSrcRemoveCmd() *cobra.Command {
|
2020-08-06 20:58:47 +03:00
|
|
|
cmd := &cobra.Command{
|
2021-02-22 10:37:00 +03:00
|
|
|
Use: "rm @HANDLE",
|
|
|
|
Example: ` $ sq rm @my1`,
|
|
|
|
Short: "Remove data source",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: execSrcRemove,
|
|
|
|
ValidArgsFunction: completeHandle(1),
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
2021-02-22 10:37:00 +03:00
|
|
|
return cmd
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
2021-02-22 10:37:00 +03:00
|
|
|
func execSrcRemove(cmd *cobra.Command, args []string) error {
|
|
|
|
rc := RunContextFrom(cmd.Context())
|
2020-08-06 20:58:47 +03:00
|
|
|
cfg := rc.Config
|
|
|
|
src, err := cfg.Sources.Get(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = cfg.Sources.Remove(src.Handle)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = rc.ConfigStore.Save(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(rc.Out, "Removed data source ")
|
2022-12-25 07:04:18 +03:00
|
|
|
_, _ = rc.writers.fm.Hilite.Fprintf(rc.Out, "%s", src.Handle)
|
2020-08-06 20:58:47 +03:00
|
|
|
fmt.Fprintln(rc.Out)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|