func (cmd *ConfigCommand) Interpret(c *api.Context) (err error) { parts := api.SplitArgs(c.Line, " ") if len(parts) < 2 { err = fmt.Errorf("Specify a configuration file") } else if idx, ok := c.Cursh.(*shells.Indexsh); ok { filename := parts[1] err = configForIndex(idx, c, filename) } return }
func bucketForCbsh(cbsh *shells.Cbsh, c *api.Context) (err error) { if cbsh.Bucket != nil { cbsh.Bucket.Close() } parts := api.SplitArgs(c.Line, " ") if len(parts) < 2 { err = fmt.Errorf("Need argument to bucket") } else if cbsh.U == nil { err = fmt.Errorf("Not connected to any server") } else if bucket, err := cbsh.Pool.GetBucket(parts[1]); err == nil { cbsh.Bucketname, cbsh.Bucket = parts[1], bucket } return }
func getForCbsh(cbsh *shells.Cbsh, c *api.Context) (err error) { var ob interface{} parts := api.SplitArgs(c.Line, " ") if cbsh.Bucket == nil { err = fmt.Errorf("Not connected to bucket") } else if len(parts) < 2 { err = fmt.Errorf("Need argument to get") } else if err = cbsh.Bucket.Get(parts[1], &ob); err == nil { var s string s, err = api.PrettyPrint(ob, "") fmt.Fprintf(c.W, "%v\n", s) } return }
func (cmd *HelpCommand) Interpret(c *api.Context) (err error) { parts := api.SplitArgs(c.Line, " ") if len(parts) < 2 { for _, cmd := range c.Commands { fmt.Fprintf(c.W, "%-15s %s\n", cmd.Name(), cmd.Description()) } } else { cmd := c.Commands[parts[1]] fmt.Fprintln(c.W, api.Yellow(cmd.Description())) help := cmd.Help() if len(strings.Trim(help, " \t\n\r")) > 0 { fmt.Fprintln(c.W, help) } fmt.Fprintf(c.W, "shells: %v\n\n", cmd.Shells()) } return }
func connectForCbsh(cbsh *shells.Cbsh, c *api.Context) (err error) { // Close existing client connection if cbsh.Bucket != nil { cbsh.Bucket.Close() } parts := api.SplitArgs(c.Line, " ") if len(parts) < 2 { return fmt.Errorf("Need argument to connect") } else { cbsh.Url = parts[1] } if len(parts) > 2 { cbsh.Poolname = parts[2] } if len(parts) > 3 { cbsh.Bucketname = parts[3] } return cbsh.Connect(c) }