Skip to content

Commit

Permalink
fixing message routing to output commands not found
Browse files Browse the repository at this point in the history
  • Loading branch information
AC-4 committed May 19, 2024
1 parent 7b4bda6 commit e57a24a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
58 changes: 37 additions & 21 deletions src/Xcaciv.Command/CommandController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ public void EnableDefaultCommands()
FullPath = ""
}
});

var set = new SayCommand();
AddCommand(new CommandDescription()
{
BaseCommand = set.BaseCommand,
FullTypeName = set.GetType().FullName ?? String.Empty,
PackageDescription = new PackageDescription()
{
Name = key,
FullPath = ""
}
});
}
/// <summary>
/// install a single command into the index
Expand Down Expand Up @@ -199,35 +211,39 @@ protected async Task PipelineTheBitch(string commandLine, ITextIoContext ioConte
/// <param name="ioContext"></param>
protected async Task ExecuteCommand(string commandKey, ITextIoContext ioContext)
{
if (!this.Commands.ContainsKey(commandKey))
if (Commands.TryGetValue(commandKey, out CommandDescription? commandDiscription))
{
try
{
await ioContext.AddTraceMessage($"ExecuteCommand: {commandKey} Start.");

var commandInstance = GetCommandInstance(commandDiscription);

await ExecuteCommand(ioContext, commandInstance);
}
catch (Exception ex)
{
await ioContext.OutputChunk($"Error executing {commandKey} (see trace for more info)");
await ioContext.SetStatusMessage("Error");
await ioContext.AddTraceMessage(ex.ToString());
}
finally
{
await ioContext.AddTraceMessage($"ExecuteCommand: {commandKey} Done.");
}
}
else
{
if (commandKey == this.HelpCommand)
{
this.GetHelp(string.Empty, ioContext);
}
else
{
await ioContext.SetStatusMessage($"Command [{commandKey}] not found. Try typing '{this.HelpCommand}'");
var message = $"Command[{commandKey}] not found.";
await ioContext.OutputChunk($"{message} Try '{this.HelpCommand}'");
await ioContext.AddTraceMessage(message);
}
return;
}

try
{
var commandDiscription = this.Commands[commandKey];

ICommandDelegate commandInstance;
commandInstance = GetCommandInstance(commandDiscription);

await ExecuteCommand(ioContext, commandInstance);
}
catch (Exception ex)
{
await ioContext.SetStatusMessage(ex.ToString());
}
finally
{
await ioContext.AddTraceMessage($"ExecuteCommand: {commandKey} Done.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Xcaciv.Command/Xcaciv.Command.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.3.15</Version>
<Version>1.3.16</Version>
<AssemblyName>Xcaciv.Command</AssemblyName>
<RootNamespace>Xcaciv.Command</RootNamespace>
<IsPublishable>True</IsPublishable>
Expand Down

0 comments on commit e57a24a

Please sign in to comment.