@@ -29,7 +29,7 @@ public IEnumerable<Action<HelpContext>> CustomHelpLayout()
29
29
return ;
30
30
}
31
31
32
- Dictionary < bool , List < CommandLineOption > > allOptions = GetAllOptions ( ) ;
32
+ Dictionary < bool , List < CommandLineOption > > allOptions = GetAllOptions ( context . Command . Options ) ;
33
33
allOptions . TryGetValue ( true , out List < CommandLineOption > builtInOptions ) ;
34
34
allOptions . TryGetValue ( false , out List < CommandLineOption > nonBuiltInOptions ) ;
35
35
@@ -128,29 +128,36 @@ private void OnHelpRequested(object sender, HelpEventArgs args)
128
128
( isBuiltIn , value ) => [ .. value , ( moduleName , nonBuiltInOptions . ToArray ( ) ) ] ) ;
129
129
}
130
130
131
- private Dictionary < bool , List < CommandLineOption > > GetAllOptions ( )
131
+ private Dictionary < bool , List < CommandLineOption > > GetAllOptions ( IList < Option > commandOptions )
132
132
{
133
- Dictionary < bool , List < CommandLineOption > > builtInToOptions = [ ] ;
133
+ Dictionary < bool , List < CommandLineOption > > filteredOptions = [ ] ;
134
+
135
+ // Create a set of option names from the command's options for efficient lookup
136
+ var commandOptionNames = commandOptions . Select ( o => o . Name . TrimStart ( '-' ) ) . ToHashSet ( StringComparer . OrdinalIgnoreCase ) ;
134
137
135
138
foreach ( KeyValuePair < string , CommandLineOption > option in _commandLineOptionNameToModuleNames )
136
139
{
137
- if ( ! builtInToOptions . TryGetValue ( option . Value . IsBuiltIn . Value , out List < CommandLineOption > value ) )
138
- {
139
- builtInToOptions . Add ( option . Value . IsBuiltIn . Value , [ option . Value ] ) ;
140
- }
141
- else
140
+ // Only include options that are NOT already present in the command's options
141
+ if ( ! commandOptionNames . Contains ( option . Value . Name ) )
142
142
{
143
- value . Add ( option . Value ) ;
143
+ if ( ! filteredOptions . TryGetValue ( option . Value . IsBuiltIn . Value , out List < CommandLineOption > value ) )
144
+ {
145
+ filteredOptions . Add ( option . Value . IsBuiltIn . Value , [ option . Value ] ) ;
146
+ }
147
+ else
148
+ {
149
+ value . Add ( option . Value ) ;
150
+ }
144
151
}
145
152
}
146
153
147
154
// Sort options alphabetically by name
148
- foreach ( var optionsList in builtInToOptions . Values )
155
+ foreach ( var optionsList in filteredOptions . Values )
149
156
{
150
157
optionsList . Sort ( ( x , y ) => string . Compare ( x . Name , y . Name , StringComparison . OrdinalIgnoreCase ) ) ;
151
158
}
152
159
153
- return builtInToOptions ;
160
+ return filteredOptions ;
154
161
}
155
162
156
163
private static Dictionary < bool , List < ( string [ ] , string [ ] ) > > GetModulesToMissingOptions (
0 commit comments