11using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
24using CommandLine ;
35using CommandLine . Text ;
46using InEngine . Core . Scheduling ;
57
68namespace InEngine . Core
79{
8- public class AbstractPlugin : IPlugin
10+ abstract public class AbstractPlugin : IPlugin
911 {
1012 public virtual void Schedule ( ISchedule schedule )
1113 { }
@@ -20,9 +22,36 @@ public string GetUsage(string verb)
2022
2123 public virtual string GetUsageWithoutHeader ( )
2224 {
23- var helpText = new HelpText ( ) ;
24- helpText . AddOptions ( this ) ;
25- return helpText ;
25+ var verbs = GetType ( )
26+ . GetProperties ( )
27+ . ToList ( )
28+ . SelectMany ( x => {
29+ return x . GetCustomAttributes ( typeof ( VerbOptionAttribute ) , true ) . Select ( y => y as VerbOptionAttribute ) ;
30+ } ) ;
31+ var maxWidth = 0 ;
32+ foreach ( var verb in verbs )
33+ if ( verb . LongName != null && verb . LongName . Length > maxWidth )
34+ maxWidth = verb . LongName . Length ;
35+
36+ var helpTextLine = verbs . Select ( x => {
37+ var name = ( x . LongName ?? "" ) ;
38+ var padding = maxWidth - name . Length + 2 ;
39+ return $ " { name } " + string . Join ( "" , Enumerable . Range ( 0 , padding ) . Select ( y => " " ) ) + ( x . HelpText ?? "" ) ;
40+ } ) ;
41+
42+ return string . Join ( Environment . NewLine , helpTextLine ) ;
43+ }
44+
45+ public IList < VerbOptionAttribute > GetVerbOptions ( )
46+ {
47+ return GetType ( )
48+ . GetProperties ( )
49+ . SelectMany ( property => {
50+ return property . GetCustomAttributes ( typeof ( VerbOptionAttribute ) , true )
51+ . Select ( verb => verb as VerbOptionAttribute ) ;
52+ } )
53+ . OrderBy ( x => x . LongName )
54+ . ToList ( ) ;
2655 }
2756 }
2857}
0 commit comments