@@ -261,6 +261,30 @@ List only the plugin 'foo' matching a fully qualified name exactly
261261 PluginListCommandOptions m_options;
262262};
263263
264+ static void DoPluginEnableDisable (Args &command, CommandReturnObject &result,
265+ bool enable) {
266+ const char *name = enable ? " enable" : " disable" ;
267+ size_t argc = command.GetArgumentCount ();
268+ if (argc == 0 ) {
269+ result.AppendErrorWithFormat (" 'plugin %s' requires one or more arguments" ,
270+ name);
271+ return ;
272+ }
273+ result.SetStatus (eReturnStatusSuccessFinishResult);
274+
275+ for (size_t i = 0 ; i < argc; ++i) {
276+ llvm::StringRef pattern = command[i].ref ();
277+ int num_matching = SetEnableOnMatchingPlugins (pattern, result, enable);
278+
279+ if (num_matching == 0 ) {
280+ result.AppendErrorWithFormat (
281+ " Found no matching plugins to %s for pattern '%s'" , name,
282+ pattern.data ());
283+ break ;
284+ }
285+ }
286+ }
287+
264288class CommandObjectPluginEnable : public CommandObjectParsed {
265289public:
266290 CommandObjectPluginEnable (CommandInterpreter &interpreter)
@@ -273,23 +297,7 @@ class CommandObjectPluginEnable : public CommandObjectParsed {
273297
274298protected:
275299 void DoExecute (Args &command, CommandReturnObject &result) override {
276- size_t argc = command.GetArgumentCount ();
277- if (argc == 0 ) {
278- result.AppendError (" 'plugin enable' requires one or more arguments" );
279- return ;
280- }
281- result.SetStatus (eReturnStatusSuccessFinishResult);
282-
283- for (size_t i = 0 ; i < argc; ++i)
284- {
285- llvm::StringRef pattern = command[i].ref ();
286- int num_matching = SetEnableOnMatchingPlugins (pattern, result, true );
287-
288- if (num_matching == 0 ) {
289- result.AppendErrorWithFormat (" Found no matching plugins to enable for pattern '%s'" ,pattern.data ());
290- break ;
291- }
292- }
300+ DoPluginEnableDisable (command, result, true );
293301 }
294302};
295303
@@ -305,18 +313,7 @@ class CommandObjectPluginDisable : public CommandObjectParsed {
305313
306314protected:
307315 void DoExecute (Args &command, CommandReturnObject &result) override {
308- size_t argc = command.GetArgumentCount ();
309- if (argc != 1 ) {
310- result.AppendError (" 'plugin disable' requires one argument" );
311- return ;
312- }
313- llvm::StringRef pattern = command[0 ].ref ();
314- result.SetStatus (eReturnStatusSuccessFinishResult);
315-
316- int num_matching = SetEnableOnMatchingPlugins (pattern, result, false );
317-
318- if (num_matching == 0 )
319- result.AppendErrorWithFormat (" Found no matching plugins to disable" );
316+ DoPluginEnableDisable (command, result, false );
320317 }
321318};
322319
0 commit comments