aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Command.ts
blob: b8c21ce4976763af78a94aa0f0cb00424bbc01c3 (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
export enum Command {
    Open = "open",
    TabOpen = "tabopen",
    WindowOpen = "winopen",
    Buffer = "buffer",
    BufferDelete = "bdelete",
    BufferDeleteForce = "bdelete!",
    BuffersDelete = "bdeletes",
    BuffersDeleteForce = "bdeletes!",
    AddBookmark = "addbookmark",
    Quit = "quit",
    QuitAll = "quitall",
    Set = "set",
    Help = "help",
}

export namespace Command {
  export function members(): Command[] {
    return [
      Command.Open ,
      Command.TabOpen ,
      Command.WindowOpen ,
      Command.Buffer ,
      Command.BufferDelete ,
      Command.BufferDeleteForce ,
      Command.BuffersDelete ,
      Command.BuffersDeleteForce ,
      Command.AddBookmark ,
      Command.Quit ,
      Command.QuitAll ,
      Command.Set ,
      Command.Help ,
    ]
  }

  export function valueOf(value: string): Command {
    const map = new Map(members().map(cmd => [cmd.toString(), cmd]));
    const cmd = map.get(value);
    if (!cmd) {
      throw new Error(`unknown command '${value}`);
    }
    return cmd;
  }
}