mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-26 17:51:34 +03:00
58ccfc9ded
* Type Detector refactor * json driver impl; refactoring of source.Files reader et al * working on kind detector * significant switcheroo of packages * partway throught refactoring Kind * major package switcheroo for Kind
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/neilotoole/sq/libsq/core/errz"
|
|
)
|
|
|
|
func newSrcCommand() (*cobra.Command, runFunc) {
|
|
cmd := &cobra.Command{
|
|
Use: "src [@HANDLE]",
|
|
Example: ` # get active data source
|
|
sq src
|
|
# set @my1 as active data source
|
|
sq src @my1`,
|
|
// RunE: execSrc,
|
|
Short: "Get or set active data source",
|
|
Long: `Get or set active data source. If no argument provided, get the active data
|
|
source. Otherwise, set @HANDLE as the active data source.`,
|
|
}
|
|
|
|
//cmd.Flags().BoolP(flagJSON, flagJSONShort, false, flagJSONUsage)
|
|
//cmd.Flags().BoolP(flagTable, flagTableShort, false, flagTableUsage)
|
|
//cmd.Flags().BoolP(flagHeader, flagHeaderShort, false, flagHeaderUsage)
|
|
|
|
return cmd, execSrc
|
|
}
|
|
|
|
func execSrc(rc *RunContext, cmd *cobra.Command, args []string) error {
|
|
if len(args) > 1 {
|
|
return errz.Errorf(msgInvalidArgs)
|
|
}
|
|
|
|
cfg := rc.Config
|
|
|
|
if len(args) == 0 {
|
|
// Get the active data source
|
|
src := cfg.Sources.Active()
|
|
if src == nil {
|
|
return nil
|
|
}
|
|
|
|
return rc.writers.srcw.Source(src)
|
|
}
|
|
|
|
src, err := cfg.Sources.SetActive(args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = rc.ConfigStore.Save(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return rc.writers.srcw.Source(src)
|
|
}
|