@@ -147,6 +147,7 @@ TCommandDefinition = record
147147 property Description : string read GetDescription;
148148 property Usage : string read GetUsage;
149149 property Examples : TList<string> read GetExamples;
150+ property Command : ICommandDefinition read FCommandDef;
150151
151152 end ;
152153
@@ -335,6 +336,7 @@ class procedure TOptionsRegistry.PrintUsage(const command: ICommandDefinition; c
335336 maxDescW : integer;
336337 exeName : string;
337338 i: Integer;
339+ printOption : TConstProc<IOptionDefinition>;
338340begin
339341 exeName := ChangeFileExt(ExtractFileName(ParamStr(0 )), ' ' ).ToLower();
340342 if not command.IsDefault then
@@ -364,45 +366,51 @@ class procedure TOptionsRegistry.PrintUsage(const command: ICommandDefinition; c
364366
365367 maxDescW := maxDescW - FDescriptionTab;
366368
367- command.EmumerateCommandOptions(
368- procedure(const opt : IOptionDefinition)
369- var
370- descStrings : TArray<string>;
371- i : integer;
372- numDescStrings : integer;
373- s : string;
374- begin
375- s := WrapText(opt.HelpText, sLineBreak, [' ' , ' -' , #9 , ' ,' ], maxDescW -1 );
376-
377- descStrings := s.Split([sLineBreak], TStringSplitOptions.None);
378- for i := 0 to length(descStrings) -1 do
379- descStrings[i] := Trim(descStrings[i]);
369+ printOption := procedure(const opt : IOptionDefinition)
370+ var
371+ descStrings : TArray<string>;
372+ i : integer;
373+ numDescStrings : integer;
374+ s : string;
375+ begin
376+ s := WrapText(opt.HelpText, sLineBreak, [' ' , ' -' , #9 , ' ,' ], maxDescW -1 );
377+
378+ descStrings := s.Split([sLineBreak], TStringSplitOptions.None);
379+ for i := 0 to length(descStrings) -1 do
380+ descStrings[i] := Trim(descStrings[i]);
381+
382+ if opt.IsUnnamed then
383+ s := ' <' + opt.ShortName + ' >'
384+ else
385+ begin
386+ s := ' -' + opt.LongName;
387+ if opt.ShortName <> ' ' then
388+ s := s + ' |-' + opt.ShortName ;
389+ end ;
390+
391+ if opt.HasValue then
392+ s := s + FNameValueSeparator + ' <' + opt.LongName + ' >' ;
393+ s := PadRight(s, FDescriptionTab);
394+ s := s + descStrings[0 ];
395+ proc(s);
396+ numDescStrings := Length(descStrings);
397+ if numDescStrings > 1 then
398+ begin
399+ for i := 1 to numDescStrings -1 do
400+ begin
401+ s := PadLeft(descStrings[i], FDescriptionTab);
402+ proc(s);
403+ end ;
404+ proc(' ' );
405+ end ;
406+ end ;
407+
408+ command.EmumerateCommandOptions(printOption);
380409
381- if opt.IsUnnamed then
382- s := ' <' + opt.ShortName + ' >'
383- else
384- begin
385- s := ' -' + opt.LongName;
386- if opt.ShortName <> ' ' then
387- s := s + ' |-' + opt.ShortName ;
388- end ;
410+ if not command.IsDefault then
411+ FDefaultCommand.command.EmumerateCommandOptions(printOption);
412+
389413
390- if opt.HasValue then
391- s := s + FNameValueSeparator + ' <' + opt.LongName + ' >' ;
392- s := PadRight(s, FDescriptionTab);
393- s := s + descStrings[0 ];
394- proc(s);
395- numDescStrings := Length(descStrings);
396- if numDescStrings > 1 then
397- begin
398- for i := 1 to numDescStrings -1 do
399- begin
400- s := PadLeft(descStrings[i], FDescriptionTab);
401- proc(s);
402- end ;
403- proc(' ' );
404- end ;
405- end );
406414 if command.Examples.Count > 0 then
407415 begin
408416 proc(' ' );
@@ -414,6 +422,9 @@ class procedure TOptionsRegistry.PrintUsage(const command: ICommandDefinition; c
414422 end ;
415423 end ;
416424
425+
426+
427+
417428end ;
418429
419430class procedure TOptionsRegistry.PrintUsage (const commandName: string; const proc: TConstProc<string>);
0 commit comments