@@ -27,7 +27,7 @@ public static IEnumerable<CommandInfo> FindCommands(string pkgRoot, string[] arg
27
27
return CommandDispatchHelper . MatchScore ( cmd , semiColonSeparatedArgs ) >= cmd . Length ;
28
28
} ;
29
29
30
- return FindMatches ( pkgRoot , args , matcher ) ;
30
+ return FindCommandMatches ( pkgRoot , args , matcher ) ;
31
31
}
32
32
33
33
/// <summary>
@@ -51,10 +51,34 @@ public static IEnumerable<CommandInfo> CompleteCommands(string pkgRoot, string[]
51
51
return CommandDispatchHelper . MatchScore ( cmd , semiColonSeparatedArgs ) >= semiColonSeparatedArgs . Length ;
52
52
} ;
53
53
54
- return FindMatches ( pkgRoot , args , matcher ) ;
54
+ return FindCommandMatches ( pkgRoot , args , matcher ) ;
55
55
}
56
56
57
- public static IEnumerable < CommandInfo > FindMatches ( string pkgRoot , string [ ] args , Func < string , bool > matchFunc )
57
+ public static HelpInfo FindBestHelp ( string pkgRoot , string [ ] args )
58
+ {
59
+ var semiColonSeparatedArgs = String . Join ( ";" , args ) + ";" ;
60
+
61
+ Func < string , bool > matcher = ( hlp ) =>
62
+ {
63
+ return hlp . Length <= semiColonSeparatedArgs . Length && CommandDispatchHelper . MatchScore ( hlp , semiColonSeparatedArgs ) == hlp . Length ;
64
+ } ;
65
+
66
+ return FindHelpMatches ( pkgRoot , args , matcher ) . OrderByDescending ( ( hi ) => CommandDispatchHelper . MatchScore ( hi . Discriminators , semiColonSeparatedArgs ) ) . ThenBy ( ( hi ) => hi . Discriminators ) . FirstOrDefault ( ) ;
67
+ }
68
+
69
+ public static IEnumerable < HelpInfo > FindHelpMatches ( string pkgRoot , string [ ] args , Func < string , bool > matchFunc )
70
+ {
71
+ foreach ( var helpInfo in GetPackages ( pkgRoot ) . SelectMany ( ( p ) => p . GetHelp ( ) ) )
72
+ {
73
+ var semiColonSeparatedCommand = helpInfo . Discriminators + ";" ;
74
+ if ( matchFunc ( semiColonSeparatedCommand ) )
75
+ {
76
+ yield return helpInfo ;
77
+ }
78
+ }
79
+ }
80
+
81
+ public static IEnumerable < CommandInfo > FindCommandMatches ( string pkgRoot , string [ ] args , Func < string , bool > matchFunc )
58
82
{
59
83
foreach ( var commandIndex in GetCommandIndexes ( pkgRoot ) . SelectMany ( ( s ) => { return s ; } ) )
60
84
{
@@ -130,6 +154,13 @@ public string IndexPath
130
154
}
131
155
}
132
156
157
+ public string HelpPath
158
+ {
159
+ get
160
+ {
161
+ return System . IO . Path . Combine ( Path , Version , "content" , "help" ) ;
162
+ }
163
+ }
133
164
public virtual IEnumerable < CommandInfo > GetCommands ( )
134
165
{
135
166
if ( System . IO . File . Exists ( IndexPath ) )
@@ -145,12 +176,61 @@ public virtual IEnumerable<CommandInfo> GetCommands()
145
176
return new CommandInfo [ ] { } ;
146
177
}
147
178
}
179
+
180
+ public virtual IEnumerable < HelpInfo > GetHelp ( )
181
+ {
182
+ if ( System . IO . Directory . Exists ( HelpPath ) )
183
+ {
184
+ return System . IO . Directory . EnumerateFiles ( HelpPath , "*.hlp" , System . IO . SearchOption . TopDirectoryOnly ) . Select ( ( f ) =>
185
+ {
186
+ return new HelpInfo ( f ) ;
187
+ } ) ;
188
+ }
189
+ else
190
+ {
191
+ return new HelpInfo [ ] { } ;
192
+ }
193
+ }
194
+ }
195
+
196
+ public class HelpInfo
197
+ {
198
+ private string _path ;
199
+
200
+ public HelpInfo ( string path )
201
+ {
202
+ _path = path ;
203
+
204
+ Discriminators = System . IO . Path . GetFileNameWithoutExtension ( path ) . Replace ( '.' , ';' ) ;
205
+ }
206
+
207
+ public IEnumerable < string > GetHelpContent ( )
208
+ {
209
+ if ( System . IO . File . Exists ( _path ) )
210
+ {
211
+ return System . IO . File . ReadAllLines ( _path ) ;
212
+ }
213
+ else
214
+ {
215
+ return new string [ ] { } ;
216
+ }
217
+ }
218
+
219
+ public string Discriminators { get ; private set ; }
148
220
}
149
221
150
222
public class CommandInfo
151
223
{
152
224
public PkgInfo Package { get ; set ; }
153
225
public string Discriminators { get ; set ; }
226
+
227
+ public string Commandline
228
+ {
229
+ get
230
+ {
231
+ return Discriminators . Replace ( ';' , ' ' ) ;
232
+ }
233
+ }
154
234
}
155
235
}
156
236
}
0 commit comments