Skip to content

Commit 56a702f

Browse files
committed
* Showed command parameters with padding
1 parent ba41e51 commit 56a702f

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/FlowCommandLine/CommandLine.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,39 @@ private void ShowCommandHelp ( string description, List<FlowCommandParameter> pa
198198
private void ShowParameters ( List<FlowCommandParameter> commandParameters ) {
199199
if ( commandParameters.Any ( a => a.Required ) ) {
200200
m_commandLineProvider.WriteLine ( "The following arguments are available:" );
201-
foreach ( var parameter in commandParameters.Where ( a => a.Required ) ) {
201+
var requiredParameters = commandParameters
202+
.Where ( a => a.Required )
203+
.ToList ();
204+
var maximumLength = requiredParameters
205+
.Select ( a => ( !string.IsNullOrEmpty ( a.FullName ) ? a.FullName.Count () + 2 : 0 ) + ( !string.IsNullOrEmpty ( a.ShortName ) ? a.ShortName.Count () + 1 : 0 ) )
206+
.Max ();
207+
foreach ( var parameter in requiredParameters ) {
202208
var parameters = new List<string> ();
203209
if ( !string.IsNullOrEmpty ( parameter.FullName ) ) parameters.Add ( $"--{parameter.FullName}" );
204210
if ( !string.IsNullOrEmpty ( parameter.ShortName ) ) parameters.Add ( $"-{parameter.ShortName}" );
205211

206-
m_commandLineProvider.WriteLine ( $" {string.Join ( ' ', parameters )} {parameter.Description}" );
212+
var parametersValue = string.Join ( ' ', parameters );
213+
if ( parametersValue.Length < maximumLength ) parametersValue += string.Join ( "", Enumerable.Repeat ( ' ', maximumLength - parametersValue.Length ) );
214+
215+
m_commandLineProvider.WriteLine ( $" {parametersValue} {parameter.Description}" );
207216
}
208217
}
209218
if ( commandParameters.Any ( a => !a.Required ) ) {
210219
m_commandLineProvider.WriteLine ( "The following options are available:" );
211-
foreach ( var parameter in commandParameters.Where ( a => !a.Required ) ) {
220+
221+
var nonRequiredParameters = commandParameters.Where ( a => !a.Required );
222+
var maximumLength = nonRequiredParameters
223+
.Select ( a => ( !string.IsNullOrEmpty ( a.FullName ) ? a.FullName.Count () + 2 : 0 ) + ( !string.IsNullOrEmpty ( a.ShortName ) ? a.ShortName.Count () + 1 : 0 ) )
224+
.Max ();
225+
226+
foreach ( var parameter in nonRequiredParameters ) {
212227
var parameters = new List<string> ();
213228
if ( !string.IsNullOrEmpty ( parameter.FullName ) ) parameters.Add ( $"--{parameter.FullName}" );
214229
if ( !string.IsNullOrEmpty ( parameter.ShortName ) ) parameters.Add ( $"-{parameter.ShortName}" );
215230

231+
var parametersValue = string.Join ( ' ', parameters );
232+
233+
216234
m_commandLineProvider.WriteLine ( $" {string.Join ( ' ', parameters )} {parameter.Description}" );
217235
}
218236
}

src/FlowCommandLine/FlowCommandLine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<IsTrimmable>true</IsTrimmable>
2121
<PublishTrimmed>true</PublishTrimmed>
2222
<PackageReleaseNotes>
23-
Fixed parsing values with character =
23+
Fixed padding for command parameters
2424
</PackageReleaseNotes>
2525
</PropertyGroup>
2626

src/FlowCommandLineTests/CommandLineUnitTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ public void RunCommand_NotSuccess_RequiredField () {
208208
},
209209
"",
210210
new List<FlowCommandParameter> {
211-
new FlowCommandParameter { FullName = "Parameter1", Description = "Description", Required = true }
211+
new FlowCommandParameter { FullName = "Parameter1", Description = "Description", Required = true },
212+
new FlowCommandParameter { FullName = "Parameter2", Description = "Description", Required = false }
212213
}
213214
)
214215
.RunCommand ();
@@ -219,6 +220,8 @@ public void RunCommand_NotSuccess_RequiredField () {
219220
Assert.Equal ( " ", messages.ElementAt ( 1 ) );
220221
Assert.Equal ( "The following arguments are available:", messages.ElementAt ( 2 ) );
221222
Assert.Equal ( " --Parameter1 Description", messages.ElementAt ( 3 ) );
223+
Assert.Equal ( "The following options are available:", messages.ElementAt ( 4 ) );
224+
Assert.Equal ( " --Parameter2 Description", messages.ElementAt ( 5 ) );
222225
}
223226

224227
public record RunCommand_Success_QuotedParameters_Class {

0 commit comments

Comments
 (0)