Skip to content

Commit aa3d8da

Browse files
committed
Support Alias
1 parent 7aca7db commit aa3d8da

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

shell/AIShell.Kernel/Command/ClearCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public ClearCommand()
99
: base("cls", "Clear the screen.")
1010
{
1111
this.SetHandler(ClearAction);
12+
this.AddAlias("clear");
1213
}
1314

1415
private void ClearAction()

shell/AIShell.Kernel/Command/CommandRunner.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,17 @@ internal void LoadCommands(IEnumerable<CommandBase> commands, string agentName)
5757
{
5858
command.Shell = _shell;
5959
command.Source = agentName;
60+
61+
// TODO: need to think about how to handle command names/aliases collision.
62+
// We don't handle collision today -- it will throw when collision happens.
6063
_commands.Add(command.Name, command);
64+
foreach (string alias in command.Aliases)
65+
{
66+
if (!string.IsNullOrWhiteSpace(alias))
67+
{
68+
_commands.Add(alias, command);
69+
}
70+
}
6171
}
6272
}
6373

@@ -79,7 +89,16 @@ internal void UnloadAgentCommands()
7989

8090
foreach (var command in agentCommands)
8191
{
92+
// TODO: need to update accordingly when we handle command names/aliases collision.
8293
_commands.Remove(command.Name);
94+
foreach (string alias in command.Aliases)
95+
{
96+
if (!string.IsNullOrWhiteSpace(alias))
97+
{
98+
_commands.Remove(alias);
99+
}
100+
}
101+
83102
command.Dispose();
84103
}
85104
}

0 commit comments

Comments
 (0)