diff options
| author | AShifter <[email protected]> | 2017-10-15 08:33:26 -0600 |
|---|---|---|
| committer | AShifter <[email protected]> | 2017-10-15 08:33:26 -0600 |
| commit | ed1d876aaa2cc8b0fd953d4cafb66e07e9051f3a (patch) | |
| tree | 1190cc4e0ea18ae6a530b9284a0e4f49177de24e /ShiftOS.Engine/Terminal/TerminalBackend.cs | |
| parent | 9c31cf53bee2fda60abe5b3687c3a8ed8b5e5e5c (diff) | |
| parent | b0fb6ed50e8108b4c5f4ef8614368664e79d4426 (diff) | |
| download | shiftos-rewind-ed1d876aaa2cc8b0fd953d4cafb66e07e9051f3a.tar.gz shiftos-rewind-ed1d876aaa2cc8b0fd953d4cafb66e07e9051f3a.tar.bz2 shiftos-rewind-ed1d876aaa2cc8b0fd953d4cafb66e07e9051f3a.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.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ShiftOS.Engine/Terminal/TerminalBackend.cs b/ShiftOS.Engine/Terminal/TerminalBackend.cs new file mode 100644 index 0000000..7103238 --- /dev/null +++ b/ShiftOS.Engine/Terminal/TerminalBackend.cs @@ -0,0 +1,46 @@ +using System; +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; + + /// <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); + + foreach (TerminalCommand 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(); + } + } +} |
