aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/Terminal/TerminalBackend.cs
diff options
context:
space:
mode:
authorAShifter <[email protected]>2017-11-17 20:29:46 -0700
committerAShifter <[email protected]>2017-11-17 20:29:46 -0700
commitebdc09fe679b4b06fd149c8fc6539244100ce896 (patch)
tree65dfe45bbfd194ddb534cc80107ab8e6d80cf5bc /ShiftOS.Engine/Terminal/TerminalBackend.cs
parent1d0b393e6969d9671daead8049973a374421046f (diff)
parent97722fbe9d474adffbba0b92e9727c48a8205234 (diff)
downloadshiftos-rewind-ebdc09fe679b4b06fd149c8fc6539244100ce896.tar.gz
shiftos-rewind-ebdc09fe679b4b06fd149c8fc6539244100ce896.tar.bz2
shiftos-rewind-ebdc09fe679b4b06fd149c8fc6539244100ce896.zip
Merge remote-tracking branch 'refs/remotes/ShiftOS-Rewind/master'
Diffstat (limited to 'ShiftOS.Engine/Terminal/TerminalBackend.cs')
-rw-r--r--ShiftOS.Engine/Terminal/TerminalBackend.cs71
1 files changed, 36 insertions, 35 deletions
diff --git a/ShiftOS.Engine/Terminal/TerminalBackend.cs b/ShiftOS.Engine/Terminal/TerminalBackend.cs
index 7103238..793b748 100644
--- a/ShiftOS.Engine/Terminal/TerminalBackend.cs
+++ b/ShiftOS.Engine/Terminal/TerminalBackend.cs
@@ -2,45 +2,46 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
namespace ShiftOS.Engine.Terminal
{
- public static class TerminalBackend
- {
- // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine
- public static IEnumerable<TerminalCommand> instances = from t in Assembly.GetExecutingAssembly().GetTypes()
- where t.IsSubclassOf(typeof(TerminalCommand))
- && t.GetConstructor(Type.EmptyTypes) != null
- select Activator.CreateInstance(t) as TerminalCommand;
+ public static class TerminalBackend
+ {
+ // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine
+ static readonly IEnumerable<TerminalCommand> Instances = from t in Assembly.GetExecutingAssembly().GetTypes()
+ where t.IsSubclassOf(typeof(TerminalCommand)) &&
+ t.GetConstructor(Type.EmptyTypes) != null
+ select (TerminalCommand) Activator.CreateInstance(t);
- /// <summary>
- /// Runs a terminal command.
- /// </summary>
- /// <param name="command"></param>
- /// <returns>Returns all the output from that command.</returns>
- public static string RunCommand(string command)
- {
- string name;
- try { name = command.Split(' ')[0]; } catch { name = command; }
+ /// <summary>
+ /// Runs a terminal command.
+ /// </summary>
+ /// <param name="command"></param>
+ /// <returns>Returns all the output from that command.</returns>
+ public static string RunCommand(string command)
+ {
+ string name;
+ try
+ {
+ name = command.Split(' ')[0];
+ }
+ catch
+ {
+ name = command;
+ }
- var theParams = new string[command.Split(' ').Length - 1];
- Array.Copy(command.Split(' '), 1, theParams, 0, command.Split(' ').Length - 1);
+ var theParams = new string[command.Split(' ').Length - 1];
+ Array.Copy(command.Split(' '), 1, theParams, 0, command.Split(' ').Length - 1);
- foreach (TerminalCommand instance in instances)
- {
- if (instance.GetName() == name)
- return instance.Run(theParams);
- }
+ foreach (var instance in Instances)
+ {
+ if (instance.GetName() == name)
+ {
+ return instance.Run(theParams);
+ }
+ }
- return "The command cannot be found.";
- }
-
- // An extra function ;)
- private static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
- {
- return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
- }
- }
-}
+ return "The command cannot be found.";
+ }
+ }
+} \ No newline at end of file