Framework for printing abridged manual sections in response to syntactic mistakes

This commit is contained in:
2026-03-26 16:17:06 -04:00
parent 93b396578f
commit 2bb8baac4c
12 changed files with 395 additions and 217 deletions

View File

@@ -1,5 +1,6 @@
#include "WingServer.h"
#include "WingHandler.h"
#include "WingManual.h"
#include "WingJson.h"
#include "WingLogCapture.h"
#include "WingUtils.h"
@@ -263,6 +264,8 @@ FString UWingServer::HandleRequest(const FString& Line)
LogCapture.CapturedErrors.Empty();
LogCapture.bEnabled = true;
HandlerOutput.Reset();
SuggestedManualSections.Empty();
LastHandlerClass = nullptr;
TryCallHandler(Line);
@@ -273,6 +276,11 @@ FString UWingServer::HandleRequest(const FString& Line)
UWingServer::Printf(TEXT("UE_LOG: %s\n"), *Msg);
}
LogCapture.CapturedErrors.Empty();
if (!SuggestedManualSections.IsEmpty())
{
UWingServer::SuggestManual(WingManual::Section::HandlerHelp);
WingManual::PrintManual(SuggestedManualSections, LastHandlerClass, true);
}
FString Result = HandlerOutput.ToString();
HandlerOutput.Reset();
for (int32 i = 0; i < Result.Len(); ++i)
@@ -299,6 +307,7 @@ void UWingServer::TryCallHandler(const FString &Line)
if (!Request->TryGetStringField(TEXT("command"), Command))
{
UWingServer::Printf(TEXT("Request does not contain 'command' parameter"));
UWingServer::Printf(TEXT("We recommend sending command='UserManual'."));
return;
}
Request->RemoveField(TEXT("command"));
@@ -308,8 +317,10 @@ void UWingServer::TryCallHandler(const FString &Line)
if (!HandlerClass)
{
UWingServer::Printf(TEXT("Unknown command: %s"), *Command);
UWingServer::SuggestManual(WingManual::Section::ImportantCommands);
return;
}
LastHandlerClass = *HandlerClass;
// Make an object of the handler class.
TStrongObjectPtr<UObject> HandlerObj(NewObject<UObject>(GetTransientPackage(), *HandlerClass));
@@ -318,8 +329,7 @@ void UWingServer::TryCallHandler(const FString &Line)
// Populate the handler object with the request parameters.
if (!WingJson::PopulateFromJson(HandlerObj->GetClass(), HandlerObj.Get(), &*Request))
{
UWingServer::Printf(TEXT("\nUsage:\n\n"));
WingUtils::PrintHandlerHelp(*HandlerClass);
UWingServer::SuggestManual(WingManual::Section::HandlerHelp);
return;
}