Skip to content

Commit 0d62f51

Browse files
committed
The help command now provides help for the previous command entered if no parameter is given.
1 parent 504d664 commit 0d62f51

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Runtime/DevConsoleMono.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ internal sealed class DevConsoleMono : MonoBehaviour
133133
private readonly Dictionary<string, Command> _commands = new Dictionary<string, Command>();
134134
private readonly Dictionary<Type, Func<string, object>> _parameterParseFuncs = new Dictionary<Type, Func<string, object>>();
135135
private readonly List<string> _commandHistory = new List<string>(CommandHistoryLength);
136-
private string _lastCommand = string.Empty;
136+
private string _currentCommand = string.Empty;
137+
private string _previousCommand = string.Empty;
137138
private int _commandHistoryIndex = -1;
138139
private bool _displayUnityLogs = true;
139140
private bool _displayUnityErrors = true;
@@ -475,7 +476,7 @@ internal void LogSeperator(object message = null)
475476

476477
internal void LogCommand()
477478
{
478-
LogCommand(_lastCommand);
479+
LogCommand(_currentCommand);
479480
}
480481

481482
internal void LogCommand(string name)
@@ -832,6 +833,15 @@ private void InitBuiltInCommands()
832833
}
833834

834835
LogSeperator();
836+
},
837+
() =>
838+
{
839+
if (string.IsNullOrEmpty(_previousCommand) || _previousCommand.ToLower().Equals("help"))
840+
{
841+
return;
842+
}
843+
844+
RunCommand($"help {_previousCommand}");
835845
}
836846
));
837847

@@ -848,9 +858,7 @@ private void InitBuiltInCommands()
848858
if (enumType == null)
849859
{
850860
// Search all loaded assemblies for the enum
851-
Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
852-
853-
foreach (Assembly assembly in loadedAssemblies)
861+
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
854862
{
855863
enumType = assembly.GetTypes()
856864
.SelectMany(t => t.GetMembers())
@@ -1629,7 +1637,8 @@ private object ParseParameter(string input, Type type)
16291637

16301638
private void AddToCommandHistory(string name, string input)
16311639
{
1632-
_lastCommand = name;
1640+
_previousCommand = _currentCommand;
1641+
_currentCommand = name;
16331642
_commandHistory.Insert(0, input);
16341643
if (_commandHistory.Count == CommandHistoryLength)
16351644
{

0 commit comments

Comments
 (0)