aboutsummaryrefslogtreecommitdiff
path: root/src/console/commandline/CommandParser.ts
blob: 7488cbcbcc259a7c24dc29e9a238cdeb3afb33f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Command } from "../../shared/Command";

export class UnknownCommandError extends Error {
  constructor(value: string) {
    super(`unknown command '${value}'`);
  }
}

export default class CommandParser {
  parse(value: string): Command {
    switch (value) {
      case "o":
      case "open":
        return Command.Open;
      case "t":
      case "tabopen":
        return Command.TabOpen;
      case "w":
      case "winopen":
        return Command.WindowOpen;
      case "b":
      case "buffer":
        return Command.Buffer;
      case "bd":
      case "bdel":
      case "bdelete":
        return Command.BufferDelete;
      case "bd!":
      case "bdel!":
      case "bdelete!":
        return Command.BufferDeleteForce;
      case "bdeletes":
        return Command.BuffersDelete;
      case "bdeletes!":
        return Command.BuffersDeleteForce;
      case "addbookmark":
        return Command.AddBookmark;
      case "q":
      case "quit":
        return Command.Quit;
      case "qa":
      case "quitall":
        return Command.QuitAll;
      case "set":
        return Command.Set;
      case "h":
      case "help":
        return Command.Help;
    }
    throw new UnknownCommandError(value);
  }
}