mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-19 22:21:56 +03:00
ed9aa38a67
* Expose source.Set.Data() method * jsonw.writeJSON cleaned up * sq add now respects --json * Location strings are subject to more scrutiny * Ignore .db files in project dir * sq add is more restrictive about location string * source.RedactedLocation now uses 'xxxxx' per stdlib url.URL.Redacted() * Update changelog for v0.23.0 * typos
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/neilotoole/sq/libsq/source"
|
|
"github.com/samber/lo"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newSrcRemoveCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "rm @HANDLE1 [@HANDLE2...]",
|
|
Example: ` # Remove @my1 data source
|
|
$ sq rm @my1
|
|
|
|
# Remove multiple data sources
|
|
$ sq rm @my1 @pg1 @sqlserver1`,
|
|
Short: "Remove data source",
|
|
Long: "Remove data source.",
|
|
Args: cobra.MinimumNArgs(1),
|
|
RunE: execSrcRemove,
|
|
ValidArgsFunction: completeHandle(0),
|
|
}
|
|
|
|
cmd.Flags().BoolP(flagJSON, flagJSONShort, false, flagJSONUsage)
|
|
|
|
return cmd
|
|
}
|
|
|
|
func execSrcRemove(cmd *cobra.Command, args []string) error {
|
|
rc := RunContextFrom(cmd.Context())
|
|
cfg := rc.Config
|
|
|
|
args = lo.Uniq(args)
|
|
srcs := make([]*source.Source, len(args))
|
|
for i := range args {
|
|
src, err := cfg.Sources.Get(args[i])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = cfg.Sources.Remove(src.Handle)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
srcs[i] = src
|
|
}
|
|
|
|
if err := rc.ConfigStore.Save(cfg); err != nil {
|
|
return err
|
|
}
|
|
|
|
return rc.writers.srcw.Removed(srcs...)
|
|
}
|