New Commands & piped interpreter!
This commit is contained in:
46
TermEngine/Commands/AddCommand.cs
Normal file
46
TermEngine/Commands/AddCommand.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using TermApp.Core;
|
||||
|
||||
|
||||
namespace TermApp.Commands
|
||||
{
|
||||
|
||||
|
||||
public class AddCommand : ICommand
|
||||
{
|
||||
public string Name => "add";
|
||||
public string Description => "Adds two integers together args : a + b";
|
||||
|
||||
public void Execute(string[] args, string input = null)
|
||||
{
|
||||
|
||||
if (args.Length < 1)
|
||||
{
|
||||
|
||||
Console.WriteLine(Description);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (int.TryParse(args[0], out int a) && int.TryParse(args[1], out int b))
|
||||
{
|
||||
|
||||
int result = a + b;
|
||||
Console.WriteLine(result);
|
||||
return;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Console.WriteLine("Make sure Both Args are integers!");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
26
TermEngine/Commands/ClearCommand.cs
Normal file
26
TermEngine/Commands/ClearCommand.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using TermApp.Core;
|
||||
|
||||
namespace TermApp.Commands
|
||||
{
|
||||
|
||||
public class ClearCommand : ICommand
|
||||
{
|
||||
|
||||
public string Name => "clear";
|
||||
public string Description => "Clears the Terminal";
|
||||
|
||||
public void Execute(string[] args, string input = null)
|
||||
{
|
||||
|
||||
Console.Clear();
|
||||
if (args.Length != 0)
|
||||
{
|
||||
if (args[0] == "log") Console.WriteLine("Cleared :)");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
31
TermEngine/Commands/EchoCommand.cs
Normal file
31
TermEngine/Commands/EchoCommand.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using TermApp.Core;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
namespace TermApp.Commands
|
||||
{
|
||||
|
||||
public class EchoCommand : ICommand
|
||||
{
|
||||
|
||||
public string Name => "echo";
|
||||
public string Description => "Prints Input";
|
||||
|
||||
|
||||
public void Execute(string[] args, string input = null)
|
||||
{
|
||||
|
||||
if (args.Length > 0)
|
||||
Console.WriteLine(String.Join(" ", args));
|
||||
else if (input != null)
|
||||
Console.WriteLine(input);
|
||||
else
|
||||
Console.WriteLine();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
29
TermEngine/Commands/GreetCommand.cs
Normal file
29
TermEngine/Commands/GreetCommand.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using TermApp.Core;
|
||||
|
||||
namespace TermApp.Commands
|
||||
{
|
||||
|
||||
public class GreetCommand : ICommand
|
||||
{
|
||||
public string Name => "greet";
|
||||
public string Description => "greets someone.. args [name]";
|
||||
|
||||
public void Execute(string[] args, string input = null)
|
||||
{
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
|
||||
Console.WriteLine(Description);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine("Greetings , " + args[0]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
TermEngine/Commands/HelpCommand.cs
Normal file
35
TermEngine/Commands/HelpCommand.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using TermApp.Core;
|
||||
|
||||
namespace TermApp.Commands
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class HelpCommand : ICommand
|
||||
{
|
||||
private readonly CommandInterpreter _interpreter;
|
||||
|
||||
public HelpCommand(CommandInterpreter interpreter)
|
||||
{
|
||||
|
||||
_interpreter = interpreter;
|
||||
|
||||
}
|
||||
public string Name => "help";
|
||||
public String Description => "Shows the Help pop Up";
|
||||
|
||||
public void Execute(string[] args, string input = null)
|
||||
{
|
||||
Console.WriteLine("Avaliable Commands:");
|
||||
foreach (var cmd in _interpreter.GetAllCommands())
|
||||
{
|
||||
|
||||
Console.WriteLine($"Command : {cmd.Name} | {cmd.Description}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user