Skip to content

Commit cb63b31

Browse files
committed
fixed the name of the application displayed in the help command.
1 parent 7825173 commit cb63b31

File tree

7 files changed

+31
-13
lines changed

7 files changed

+31
-13
lines changed

sources/ConsoleTools.Commando/ConsoleTools.Commando.Demo/Commands/DummyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace DustInTheWind.ConsoleTools.Commando.Demo.Commands
2121
[Command("dummy", ShortDescription = "A dummy command that shows how to use Commando.")]
2222
public class DummyCommand : ICommand
2323
{
24-
[CommandParameter(Name = "text", ShortName = 't', IsOptional = true)]
24+
[CommandParameter(Name = "text", ShortName = 't', IsOptional = false)]
2525
public string DummyText { get; set; }
2626

2727
public Task Execute()

sources/ConsoleTools.Commando/ConsoleTools.Commando.Demo/ConsoleTools.Commando.Demo.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
ConsoleTools.Commando
33
Copyright (C) 2022 Dust in the Wind
44
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
<PropertyGroup>
2222
<OutputType>Exe</OutputType>
2323
<TargetFramework>net5.0</TargetFramework>
24-
<AssemblyName>DustInTheWind.ConsoleTools.Commando.Demo</AssemblyName>
24+
<AssemblyName>CommandoDemo</AssemblyName>
2525
<RootNamespace>DustInTheWind.ConsoleTools.Commando.Demo</RootNamespace>
2626
</PropertyGroup>
2727

sources/ConsoleTools.Commando/ConsoleTools.Commando/Application.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reflection;
45
using System.Threading.Tasks;
56

67
namespace DustInTheWind.ConsoleTools.Commando
@@ -9,10 +10,16 @@ public class Application
910
{
1011
private readonly CommandRouter commandRouter;
1112

13+
public string Name { get; set; }
14+
1215
public Application(CommandRouter commandRouter)
1316
{
1417
this.commandRouter = commandRouter ?? throw new ArgumentNullException(nameof(commandRouter));
1518
commandRouter.CommandCreated += HandleCommandCreated;
19+
20+
Assembly assembly = Assembly.GetEntryAssembly();
21+
AssemblyName assemblyName = assembly?.GetName();
22+
Name = assemblyName?.Name;
1623
}
1724

1825
private static void HandleCommandCreated(object? sender, CommandCreatedEventArgs e)

sources/ConsoleTools.Commando/ConsoleTools.Commando/Commands/Help/CommandFullInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class CommandFullInfo
2525

2626
public CommandUsageViewModel Usage { get; }
2727

28-
public CommandFullInfo(CommandInfo commandInfo)
28+
public CommandFullInfo(CommandInfo commandInfo, string applicationName)
2929
{
3030
Description = commandInfo.DescriptionLines.ToList();
31-
Usage = new CommandUsageViewModel(commandInfo);
31+
Usage = new CommandUsageViewModel(commandInfo, applicationName);
3232
}
3333
}
3434
}

sources/ConsoleTools.Commando/ConsoleTools.Commando/Commands/Help/CommandUsageViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@ namespace DustInTheWind.ConsoleTools.Commando.Commands.Help
2323
public class CommandUsageViewModel
2424
{
2525
private readonly CommandInfo commandInfo;
26+
private readonly string applicationName;
2627

27-
public CommandUsageViewModel(CommandInfo commandInfo)
28+
public CommandUsageViewModel(CommandInfo commandInfo, string applicationName)
2829
{
2930
this.commandInfo = commandInfo;
31+
this.applicationName = applicationName;
3032
}
3133

3234
public override string ToString()
3335
{
3436
if (commandInfo == null)
3537
return string.Empty;
3638

37-
StringBuilder sb = new($"velo {commandInfo.Name}");
39+
StringBuilder sb = new($"{applicationName} {commandInfo.Name}");
3840

3941
IEnumerable<CommandParameterViewModel> ordinalParameters = commandInfo.ParameterInfos
4042
.Where(x => x.Order != null)

sources/ConsoleTools.Commando/ConsoleTools.Commando/Commands/Help/HelpCommand.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,34 @@ namespace DustInTheWind.ConsoleTools.Commando.Commands.Help
2525
public class HelpCommand : ICommand
2626
{
2727
private readonly AvailableCommands availableCommands;
28+
private readonly Application application;
2829

2930
[CommandParameter(DisplayName = "command name", Order = 1, IsOptional = true)]
3031
public string CommandName { get; set; }
3132

3233
public List<CommandShortInfo> Commands { get; private set; }
3334

3435
public CommandFullInfo CommandDetails { get; private set; }
36+
37+
public string ApplicationName { get; private set; }
3538

36-
public HelpCommand(AvailableCommands availableCommands)
39+
public HelpCommand(AvailableCommands availableCommands, Application application)
3740
{
3841
this.availableCommands = availableCommands ?? throw new ArgumentNullException(nameof(availableCommands));
42+
this.application = application ?? throw new ArgumentNullException(nameof(application));
3943
}
4044

4145
public Task Execute()
4246
{
4347
if (CommandName != null)
48+
{
4449
CommandDetails = GetCommandDetails(CommandName);
50+
}
4551
else
52+
{
4653
Commands = GetAllCommandDetails();
54+
ApplicationName = application.Name;
55+
}
4756

4857
return Task.CompletedTask;
4958
}
@@ -55,7 +64,7 @@ private CommandFullInfo GetCommandDetails(string commandName)
5564
if (commandInfo == null)
5665
throw new CommandNotFoundException(commandName);
5766

58-
return new CommandFullInfo(commandInfo);
67+
return new CommandFullInfo(commandInfo, application.Name);
5968
}
6069

6170
private List<CommandShortInfo> GetAllCommandDetails()

sources/ConsoleTools.Commando/ConsoleTools.Commando/Commands/Help/HelpView.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public class HelpView : IView<HelpCommand>
2626
public void Display(HelpCommand command)
2727
{
2828
if (command.Commands is { Count: > 0 })
29-
DisplayCommandsOverview(command.Commands);
29+
DisplayCommandsOverview(command);
3030
else if (command.CommandDetails != null)
3131
DisplayCommandDetails(command.CommandDetails);
3232
}
3333

34-
private static void DisplayCommandsOverview(IEnumerable<CommandShortInfo> commands)
34+
private static void DisplayCommandsOverview(HelpCommand command)
3535
{
36-
Console.WriteLine("usage: velo [command]");
36+
Console.WriteLine($"usage: {command.ApplicationName} [command]");
3737
Console.WriteLine();
3838
Console.WriteLine();
3939
Console.WriteLine("Available commands:");
@@ -48,7 +48,7 @@ private static void DisplayCommandsOverview(IEnumerable<CommandShortInfo> comman
4848
Column column = dataGrid.Columns.Add(new Column());
4949
column.CellPaddingLeft = 0;
5050

51-
IEnumerable<ContentRow> rows = commands.Select(CreateContentRow);
51+
IEnumerable<ContentRow> rows = command.Commands.Select(CreateContentRow);
5252
dataGrid.Rows.AddRange(rows);
5353

5454
dataGrid.Display();

0 commit comments

Comments
 (0)