mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-26 01:34:43 +03:00
a1ba6578da
* renamed cmdFlagChanged to flagChanged * initial stdin stuff working * wip: mostly working as expected * Docs and lots of cleanup * Mostly docs * fixed behavior of source.LocationWithPassword, and tests
46 lines
848 B
Go
46 lines
848 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newSrcRemoveCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "rm @HANDLE",
|
|
Example: ` $ sq rm @my1`,
|
|
Short: "Remove data source",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: execSrcRemove,
|
|
ValidArgsFunction: completeHandle(1),
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func execSrcRemove(cmd *cobra.Command, args []string) error {
|
|
rc := RunContextFrom(cmd.Context())
|
|
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 ")
|
|
_, _ = rc.writers.fm.Hilite.Fprintf(rc.Out, "%s", src.Handle)
|
|
fmt.Fprintln(rc.Out)
|
|
|
|
return nil
|
|
}
|