Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing message routing to output commands not found #19

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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