diff options
| author | John T <[email protected]> | 2017-11-05 18:47:46 -0500 |
|---|---|---|
| committer | John T <[email protected]> | 2017-11-05 18:47:46 -0500 |
| commit | a10440a45c40652b13e883aec832a0c8ded685e8 (patch) | |
| tree | ab64311e47f8e59c7c46cd50c94bec424165ecc2 /ShiftOS.Engine/Terminal | |
| parent | 019da5b9ebf67b758a31dd05c4b17de66fa682f2 (diff) | |
| download | shiftos-rewind-a10440a45c40652b13e883aec832a0c8ded685e8.tar.gz shiftos-rewind-a10440a45c40652b13e883aec832a0c8ded685e8.tar.bz2 shiftos-rewind-a10440a45c40652b13e883aec832a0c8ded685e8.zip | |
Added a half-complete ShiftFS and did some code cleanup
Diffstat (limited to 'ShiftOS.Engine/Terminal')
| -rw-r--r-- | ShiftOS.Engine/Terminal/Commands/Hello.cs | 26 | ||||
| -rw-r--r-- | ShiftOS.Engine/Terminal/TerminalBackend.cs | 71 | ||||
| -rw-r--r-- | ShiftOS.Engine/Terminal/TerminalCommand.cs | 20 |
3 files changed, 50 insertions, 67 deletions
diff --git a/ShiftOS.Engine/Terminal/Commands/Hello.cs b/ShiftOS.Engine/Terminal/Commands/Hello.cs index 531bd1f..7d4b82f 100644 --- a/ShiftOS.Engine/Terminal/Commands/Hello.cs +++ b/ShiftOS.Engine/Terminal/Commands/Hello.cs @@ -1,21 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShiftOS.Engine.Terminal.Commands +namespace ShiftOS.Engine.Terminal.Commands { - public class Hello : TerminalCommand - { - public override string GetName() - { - return "Hello"; - } + public class Hello : TerminalCommand + { + public override string GetName() => "Hello"; - public override string Run(params string[] parameters) - { - return "Oh, HELLO, " + String.Join(" ", parameters); - } - } -} + public override string Run(params string[] parameters) => "Oh, HELLO, " + string.Join(" ", parameters); + } +}
\ No newline at end of file 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 diff --git a/ShiftOS.Engine/Terminal/TerminalCommand.cs b/ShiftOS.Engine/Terminal/TerminalCommand.cs index a344122..81a34b9 100644 --- a/ShiftOS.Engine/Terminal/TerminalCommand.cs +++ b/ShiftOS.Engine/Terminal/TerminalCommand.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShiftOS.Engine.Terminal +namespace ShiftOS.Engine.Terminal { - public abstract class TerminalCommand - { - public abstract string GetName(); + public abstract class TerminalCommand + { + public abstract string GetName(); - public abstract string Run(params string[] parameters); - } -} + public abstract string Run(params string[] parameters); + } +}
\ No newline at end of file |
