execute special command. line must start with '%'
(ir *interp.Interp, outerr OutErr, line string)
| 724 | |
| 725 | // execute special command. line must start with '%' |
| 726 | func evalSpecialCommand(ir *interp.Interp, outerr OutErr, line string) { |
| 727 | const help string = ` |
| 728 | available special commands (%): |
| 729 | %cd [path] |
| 730 | %go111module {on|off} |
| 731 | %help |
| 732 | |
| 733 | execute shell commands ($): $command [args...] |
| 734 | example: |
| 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 '$' |
| 773 | func evalShellCommand(ir *interp.Interp, outerr OutErr, line string) { |
no test coverage detected