Skip to content

Commit b10735a

Browse files
authored
Add /clear as an alias to /cls (#370)
1 parent 7aca7db commit b10735a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

shell/AIShell.Kernel/Command/ClearCommand.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ namespace AIShell.Kernel.Commands;
66
internal sealed class ClearCommand : CommandBase
77
{
88
public ClearCommand()
9-
: base("cls", "Clear the screen.")
9+
: base("clear", "Clear the screen.")
1010
{
1111
this.SetHandler(ClearAction);
12+
this.AddAlias("cls");
1213
}
1314

1415
private void ClearAction()

shell/AIShell.Kernel/Command/CommandRunner.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ internal void LoadCommands(IEnumerable<CommandBase> commands, string agentName)
5757
{
5858
command.Shell = _shell;
5959
command.Source = agentName;
60-
_commands.Add(command.Name, command);
60+
61+
// The 'command.Name' is included in the 'command.Aliases' collection.
62+
// TODO: need to think about how to handle command names/aliases collision.
63+
// We don't handle collision today -- it will throw when collision happens.
64+
foreach (string alias in command.Aliases)
65+
{
66+
_commands.Add(alias, command);
67+
}
6168
}
6269
}
6370

@@ -79,7 +86,13 @@ internal void UnloadAgentCommands()
7986

8087
foreach (var command in agentCommands)
8188
{
82-
_commands.Remove(command.Name);
89+
// The 'command.Name' is included in the 'command.Aliases' collection.
90+
// TODO: need to update accordingly when we handle command names/aliases collision.
91+
foreach (string alias in command.Aliases)
92+
{
93+
_commands.Remove(alias);
94+
}
95+
8396
command.Dispose();
8497
}
8598
}

shell/AIShell.Kernel/Command/HelpCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private void HelpAction()
1717
var host = shellImpl.Host;
1818

1919
var commands = shellImpl.CommandRunner.Commands;
20-
var list = commands.Values.Order(new CommandComparer()).ToList();
20+
var list = commands.Values.Distinct().Order(new CommandComparer()).ToList();
2121

2222
host.WriteLine();
2323
host.MarkupLine("[bold white]-[/] Type then press [bold olive underline]Enter[/] to chat with the chosen AI agent.");

0 commit comments

Comments
 (0)