Commands are parsed with a bash-style syntax by default
This commit is contained in:
parent
81f10b0686
commit
a3cd6c0e60
4 changed files with 34 additions and 33 deletions
|
@ -260,23 +260,17 @@ namespace ShiftOS.WinForms.Applications
|
|||
}
|
||||
else
|
||||
{
|
||||
if (CurrentCommandParser.parser == null)
|
||||
var result = SkinEngine.LoadedSkin.CurrentParser.ParseCommand(text3);
|
||||
|
||||
if (result.Equals(default(KeyValuePair<string, Dictionary<string, string>>)))
|
||||
{
|
||||
TerminalBackend.InvokeCommand(text3);
|
||||
Console.WriteLine("{ERR_SYNTAXERROR}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = CurrentCommandParser.parser.ParseCommand(text3);
|
||||
|
||||
if (result.Equals(default(KeyValuePair<KeyValuePair<string, string>, Dictionary<string, string>>)))
|
||||
{
|
||||
Console.WriteLine("Syntax Error: Syntax Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
TerminalBackend.InvokeCommand(result.Key.Key, result.Key.Value, result.Value);
|
||||
}
|
||||
TerminalBackend.InvokeCommand(result.Key, result.Value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (TerminalBackend.PrefixEnabled)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")]
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue