예제 #1
0
파일: main.go 프로젝트: prataprc/gocbsh
func main() {
	createDataDir()
	// Construct the context
	context := api.Context{
		W:        os.Stdout,
		Shells:   shells.Allshells(),
		Commands: commands.Allcommands(),
	}
	argParse(&context)
	if err := context.SetShell(context.Shells[option.shell]); err != nil {
		fmt.Fprintln(context.W, err)
	}
	context.Liner = liner.NewLiner()

	// Execute command if supplied through command-line
	if option.cmdstr != "" {
		if err := doCommand(&context, option.cmdstr); err != nil {
			fmt.Fprintln(context.W, err)
		}
	} else {
		option.interactive = true
	}

	go signalCatcher(&context)
	if option.interactive {
		interactiveLoop(&context)
	}
	(&context).Close()
}
예제 #2
0
파일: main.go 프로젝트: prataprc/gocbsh
func doCommand(c *api.Context, line string) (err error) {
	// Switch shells if need be
	switch {
	case strings.HasPrefix(line, api.SHELL_CB):
		err = c.SetShell(c.Shells[api.SHELL_CB])
	case strings.HasPrefix(line, api.SHELL_N1QL):
		err = c.SetShell(c.Shells[api.SHELL_N1QL])
	case strings.HasPrefix(line, api.SHELL_INDEX):
		err = c.SetShell(c.Shells[api.SHELL_INDEX])
	default:
		c.Line = line
		// Handle the command for the current shell
		err = handleShellCommand(c)
	}
	return
}