-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.cs
More file actions
53 lines (51 loc) · 1.6 KB
/
Engine.cs
File metadata and controls
53 lines (51 loc) · 1.6 KB
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
53
using System;
using System.IO;
namespace Cmd
{
internal class Engine
{
private string _currentDirectory = Directory.GetCurrentDirectory();
public void MainLoop()
{
var dones = true;
while (dones)
{
ShowCurrentDirectory();
var inputString = Console.ReadLine();
var comand = ParseComand(inputString);
switch (comand)
{
case Command.StrExit:
dones = false;
break;
case Command.StrDir:
var dir = new Dir(inputString);
dir.Execute();
break;
case Command.StrCd:
var cd = new Cd(inputString);
cd.Execute();
break;
default:
Console.WriteLine("Error");
break;
}
}
}
private void ShowCurrentDirectory()
{
_currentDirectory = Directory.GetCurrentDirectory();
Console.Write("\n" + _currentDirectory + ">");
}
private static string ParseComand(string command)
{
if(command.StartsWith("dir"))
return Command.StrDir;
if (command.StartsWith("cd "))
return Command.StrCd;
if (command.StartsWith("exit"))
return Command.StrExit;
return Command.ErrorCommand;
}
}
}