aboutsummaryrefslogtreecommitdiff
path: root/src/console/commandline/CommandParser.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-04-09 10:38:37 +0900
committerGitHub <noreply@github.com>2020-04-09 10:38:37 +0900
commit1656d52d2cefb3846d968c6117484e6aefe7dabe (patch)
treeab58a99b832d2571e2168f2ee0e328bc12d9580e /src/console/commandline/CommandParser.ts
parentc6c2da8547891b50aef2f08e5f36d258183831ff (diff)
parent5176643e64d8f4a6be5fc73f0eb48dc65322e496 (diff)
Merge pull request #730 from ueokande/refactor-console-and-completion
Refactor console and completions
Diffstat (limited to 'src/console/commandline/CommandParser.ts')
-rw-r--r--src/console/commandline/CommandParser.ts52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/console/commandline/CommandParser.ts b/src/console/commandline/CommandParser.ts
new file mode 100644
index 0000000..5228c77
--- /dev/null
+++ b/src/console/commandline/CommandParser.ts
@@ -0,0 +1,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);
+ }
+}