@@ -197,20 +197,49 @@ List only the plugin 'foo' matching a fully qualified name exactly
197197protected:
198198 void DoExecute (Args &command, CommandReturnObject &result) override {
199199 size_t argc = command.GetArgumentCount ();
200- if (argc > 1 ) {
201- result.AppendError (" 'plugin list' requires zero or one arguments" );
202- return ;
203- }
204- llvm::StringRef pattern = argc ? command[0 ].ref () : " " ;
205200 result.SetStatus (eReturnStatusSuccessFinishResult);
206201
207- bool found_matching = false ;
208- if (m_options.m_json_format ) {
209- llvm::json::Object obj = PluginManager::GetJSON (pattern);
210- found_matching = obj.size () > 0 ;
211- if (found_matching)
212- result.AppendMessage (ConvertJSONToPrettyString (std::move (obj)));
213- } else {
202+ // Create a temporary vector to hold the patterns to simplify the logic
203+ // for the case when the user passes no patterns
204+ std::vector<llvm::StringRef> patterns;
205+ patterns.reserve (argc == 0 ? 1 : argc);
206+ if (argc == 0 )
207+ patterns.push_back (" " );
208+ else
209+ for (size_t i = 0 ; i < argc; ++i)
210+ patterns.push_back (command[i].ref ());
211+
212+ if (m_options.m_json_format )
213+ OutputJsonFormat (patterns, result);
214+ else
215+ OutputTextFormat (patterns, result);
216+ }
217+
218+ private:
219+ void OutputJsonFormat (const std::vector<llvm::StringRef> &patterns,
220+ CommandReturnObject &result) {
221+ llvm::json::Object obj;
222+ bool found_empty = false ;
223+ for (const llvm::StringRef pattern : patterns) {
224+ llvm::json::Object pat_obj = PluginManager::GetJSON (pattern);
225+ if (pat_obj.empty ()) {
226+ found_empty = true ;
227+ result.AppendErrorWithFormat (
228+ " Found no matching plugins for pattern '%s'" , pattern.data ());
229+ break ;
230+ }
231+ for (auto &entry : pat_obj) {
232+ obj[entry.first ] = std::move (entry.second );
233+ }
234+ }
235+ if (!found_empty) {
236+ result.AppendMessage (ConvertJSONToPrettyString (std::move (obj)));
237+ }
238+ }
239+
240+ void OutputTextFormat (const std::vector<llvm::StringRef> &patterns,
241+ CommandReturnObject &result) {
242+ for (const llvm::StringRef pattern : patterns) {
214243 int num_matching = ActOnMatchingPlugins (
215244 pattern, [&](const PluginNamespace &plugin_namespace,
216245 const std::vector<RegisteredPluginInfo> &plugins) {
@@ -221,11 +250,12 @@ List only the plugin 'foo' matching a fully qualified name exactly
221250 plugin.name .data (), plugin.description .data ());
222251 }
223252 });
224- found_matching = num_matching > 0 ;
253+ if (num_matching == 0 ) {
254+ result.AppendErrorWithFormat (
255+ " Found no matching plugins for pattern '%s'" , pattern.data ());
256+ break ;
257+ }
225258 }
226-
227- if (!found_matching)
228- result.AppendErrorWithFormat (" Found no matching plugins" );
229259 }
230260
231261 PluginListCommandOptions m_options;
0 commit comments