diff options
| author | Michael <[email protected]> | 2017-06-17 21:03:27 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-06-17 21:03:27 -0400 |
| commit | a3cd6c0e6045d12f0cb8c9355bcd50f12e367f3b (patch) | |
| tree | 9ffc62b370eaeb24255453c5bda0ace2558c1277 /ShiftOS_TheReturn | |
| parent | 81f10b0686fed7254af3f43d15ad39fe44a48de3 (diff) | |
| download | shiftos_thereturn-a3cd6c0e6045d12f0cb8c9355bcd50f12e367f3b.tar.gz shiftos_thereturn-a3cd6c0e6045d12f0cb8c9355bcd50f12e367f3b.tar.bz2 shiftos_thereturn-a3cd6c0e6045d12f0cb8c9355bcd50f12e367f3b.zip | |
Commands are parsed with a bash-style syntax by default
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/CommandParser.cs | 29 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/Skinning.cs | 3 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/TerminalBackend.cs | 17 |
3 files changed, 28 insertions, 21 deletions
diff --git a/ShiftOS_TheReturn/CommandParser.cs b/ShiftOS_TheReturn/CommandParser.cs index 868d27a..da1073f 100644 --- a/ShiftOS_TheReturn/CommandParser.cs +++ b/ShiftOS_TheReturn/CommandParser.cs @@ -85,10 +85,9 @@ namespace ShiftOS.Engine /// </summary> /// <param name="cdd">The command string to parse.</param> /// <returns>The parsed command, ready to be invoked.</returns> - public KeyValuePair<KeyValuePair<string, string>, Dictionary<string, string>> ParseCommand(string cdd) + public KeyValuePair<string, Dictionary<string, string>> ParseCommand(string cdd) { string command = ""; - string ns = ""; Dictionary<string, string> arguments = new Dictionary<string, string>(); string text = cdd; @@ -142,12 +141,7 @@ namespace ShiftOS.Engine if (part is CommandFormatMarker) { - if (part is CommandFormatNamespace) - { - ns = res; - help = -1; - } - else if (part is CommandFormatCommand) + if (part is CommandFormatCommand) { command = res; help = -1; @@ -197,7 +191,7 @@ namespace ShiftOS.Engine if (command == "+FALSE+") { //lblExampleCommand.Text = "Syntax Error"; - return new KeyValuePair<KeyValuePair<string, string>, Dictionary<string, string>>(); + return new KeyValuePair<string, Dictionary<string, string>>(); } else { @@ -210,9 +204,24 @@ namespace ShiftOS.Engine argvs += "}"; lblExampleCommand.Text = command + argvs;*/ - return new KeyValuePair<KeyValuePair<string, string>, Dictionary<string, string>>(new KeyValuePair<string, string>(ns, command), arguments); + return new KeyValuePair<string, Dictionary<string, string>>(command, arguments); } } + + internal static CommandParser GenerateSample() + { + var parser = new CommandParser(); + parser.AddPart(new CommandFormatCommand()); + parser.AddPart(new CommandFormatText(" --")); + parser.AddPart(new CommandFormatArgument()); + parser.AddPart(new CommandFormatText(" ")); + parser.AddPart(new CommandFormatValue()); + parser.AddPart(new CommandFormatText(" --")); + parser.AddPart(new CommandFormatArgument()); + parser.AddPart(new CommandFormatText(" ")); + parser.AddPart(new CommandFormatValue()); + return parser; + } } public class CFValue diff --git a/ShiftOS_TheReturn/Skinning.cs b/ShiftOS_TheReturn/Skinning.cs index ab2d6b1..e00a2ef 100644 --- a/ShiftOS_TheReturn/Skinning.cs +++ b/ShiftOS_TheReturn/Skinning.cs @@ -637,6 +637,9 @@ namespace ShiftOS.Engine [ShifterDescription("The maximize button color")] public Color MaximizeButtonColor = Accent1; + [ShifterHidden] + public CommandParser CurrentParser = CommandParser.GenerateSample(); + [ShifterMeta("Windows")] [ShifterCategory("Title Buttons")] [ShifterName("Minimize Button Color")] diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index 1ca31e0..d60b675 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -92,30 +92,25 @@ namespace ShiftOS.Engine /// <summary> /// Invokes a ShiftOS terminal command. /// </summary> - /// <param name="ns">The command's namespace.</param> /// <param name="command">The command name.</param> /// <param name="arguments">The command arguments.</param> /// <param name="isRemote">Whether the command should be sent through Remote Terminal Session (RTS).</param> - public static void InvokeCommand(string ns, string command, Dictionary<string, string> arguments, bool isRemote = false) + public static void InvokeCommand(string command, Dictionary<string, string> arguments, bool isRemote = false) { try { - if (string.IsNullOrWhiteSpace(ns)) - return; - + bool commandWasClient = RunClient(command, arguments, isRemote); - bool commandWasClient = RunClient(ns, command, arguments, isRemote); - - if (!commandWasClient && !string.IsNullOrWhiteSpace(ns)) + if (!commandWasClient) { - Console.WriteLine("Error: Command not found."); + Console.WriteLine("{ERR_COMMANDNOTFOUND}"); } - CommandProcessed?.Invoke(ns + "." + command, JsonConvert.SerializeObject(arguments)); + CommandProcessed?.Invoke(command, JsonConvert.SerializeObject(arguments)); } catch (Exception ex) { - Console.WriteLine($"Command parse error: {ex.Message}"); // This shouldn't ever be called now + Console.WriteLine("{ERR_SYNTAXERROR}"); PrefixEnabled = true; } |
