Skip to content

Commit 171124e

Browse files
committed
Finalizing fixes
1 parent 319f692 commit 171124e

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/CommandLine/Text/HelpText.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,14 @@ public static string RenderUsageText<T>(ParserResult<T> parserResult)
430430
{
431431
if (parserResult == null) throw new ArgumentNullException("parserResult");
432432

433-
var examples = GetUsageFromType(parserResult.TypeInfo.Current)
434-
.Return(x => x, Enumerable.Empty<Example>());
435-
if (examples.Empty())
433+
var usage = GetUsageFromType(parserResult.TypeInfo.Current);
434+
if (usage.MatchNothing())
436435
return string.Empty;
437436

437+
var usageTuple = usage.FromJust();
438+
var examples = usageTuple.Item2;
439+
var appAlias = usageTuple.Item1.ApplicationAlias ?? ReflectionHelper.GetAssemblyName();
440+
438441
var text = new StringBuilder();
439442
foreach (var e in examples)
440443
{
@@ -447,6 +450,8 @@ public static string RenderUsageText<T>(ParserResult<T> parserResult)
447450
{
448451
var commandLine = new StringBuilder()
449452
.Append(2.Spaces())
453+
.Append(appAlias)
454+
.Append(' ')
450455
.Append(Parser.Default.FormatCommandLine(e.Sample,
451456
config =>
452457
{
@@ -540,7 +545,7 @@ private IEnumerable<Specification> GetSpecificationsFromType(Type type)
540545
.Concat(valueSpecs);
541546
}
542547

543-
private static Maybe<IEnumerable<Example>> GetUsageFromType(Type type)
548+
private static Maybe<Tuple<UsageAttribute, IEnumerable<Example>>> GetUsageFromType(Type type)
544549
{
545550
return type.GetUsageData().Map(
546551
tuple =>
@@ -550,14 +555,15 @@ private static Maybe<IEnumerable<Example>> GetUsageFromType(Type type)
550555

551556
var examples = (IEnumerable<Example>)prop
552557
.GetValue(null, BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty, null, null, null);
553-
var groups = attr.Groups;
554-
555-
return examples.Select(example => groups.ContainsKey(example.Group)
556-
? example.WithGroupDescription(groups[example.Group])
557-
: example)
558-
.OrderBy(x => x.Group)
559-
.ThenBy(x => x.GroupDescription)
560-
.Memorize();
558+
//var groups = attr.Groups;
559+
560+
//return examples.Select(example => groups.ContainsKey(example.Group)
561+
// ? example.WithGroupDescription(groups[example.Group])
562+
// : example)
563+
// .OrderBy(x => x.Group)
564+
// .ThenBy(x => x.GroupDescription)
565+
// .Memorize();
566+
return Tuple.Create(attr, examples);
561567
});
562568
}
563569

src/CommandLine/Text/UsageAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace CommandLine.Text
88
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
99
public sealed class UsageAttribute : Attribute
1010
{
11-
public UsageAttribute()
12-
{
13-
}
11+
public string ApplicationAlias { get; set; }
1412
}
1513
}

0 commit comments

Comments
 (0)