MCPcopy Index your code
hub / github.com/gopherdata/gophernotes / evalSpecialCommand

Function evalSpecialCommand

kernel.go:726–770  ·  view source on GitHub ↗

execute special command. line must start with '%'

(ir *interp.Interp, outerr OutErr, line string)

Source from the content-addressed store, hash-verified

724
725// execute special command. line must start with '%'
726func evalSpecialCommand(ir *interp.Interp, outerr OutErr, line string) {
727 const help string = `
728available special commands (%):
729%cd [path]
730%go111module {on|off}
731%help
732
733execute shell commands ($): $command [args...]
734example:
735$ls -l
736`
737
738 args := strings.SplitN(line, " ", 2)
739 cmd := args[0]
740 arg := ""
741 if len(args) > 1 {
742 arg = args[1]
743 }
744 switch cmd {
745 case "%cd":
746 if arg == "" {
747 home, err := os.UserHomeDir()
748 if err != nil {
749 panic(fmt.Errorf("error getting user home directory: %v", err))
750 }
751 arg = home
752 }
753 err := os.Chdir(arg)
754 if err != nil {
755 panic(fmt.Errorf("error setting current directory to %q: %v", arg, err))
756 }
757 case "%go111module":
758 if arg == "on" {
759 ir.Comp.CompGlobals.Options |= base.OptModuleImport
760 } else if arg == "off" {
761 ir.Comp.CompGlobals.Options &^= base.OptModuleImport
762 } else {
763 panic(fmt.Errorf("special command %s: expecting a single argument 'on' or 'off', found: %q", cmd, arg))
764 }
765 case "%help":
766 outerr.out.Write([]byte(help))
767 default:
768 panic(fmt.Errorf("unknown special command: %q\n%s", line, help))
769 }
770}
771
772// execute shell command. line must start with '$'
773func evalShellCommand(ir *interp.Interp, outerr OutErr, line string) {

Callers 1

evalSpecialCommandsFunction · 0.85

Calls 1

WriteMethod · 0.80

Tested by

no test coverage detected