[Yum-devel] [PATCH]: allow plugins to add new commands to the cli
Bastiaan Bakker
bastiaan.bakker at enovation.nl
Tue Sep 12 21:00:26 UTC 2006
On Tuesday 12 September 2006 18:52, Menno Smits wrote:
> Hi Bastiaan,
>
> > While trying to reimplemnt yum-builddep as a plugin I noticed that it's
> > not yet possible for a plugin to add new commands to the cli.
> > Attached is a patch against HEAD that enables plugins to register new
> > commands.
>
> Thanks for the patch. This has been a longstanding TODO that I've
> never gotten around to.
>
> I think the overall approach is good. Separating out doCommands into
> individual methods makes a lot of sense regardless and the new
> registerCommand() method fits in well with the rest of the plugin API.
>
> I'm not too keen on the struture of yum_cli_commands. The 'checks'
> attribute is a little klunky and inflexible. Why not just have the
> handler method for a command call checkRootUID/checkGPGKey/whatever
> as required? I think this would be much clearer. Plugins would have
> access to these check methods via the base object too.
>
Agreed. Sometimes when you start parameterizing stuff you can't stop :-)
> yum_cli_commands would then be simplified to something like:
> {
> 'update': self.doUpdateMethod,
> 'install': self.doInstallMethod,
> ...
> }
>
Well, I separated the checks from the handler method in order to have all
checks completed before cli.doCommands would be called. I assumed this is
desirable, else why bother with a separate parseCommands method?
> Also there's a bug in registerCommand():
> > + def registerCommand(self, name, command, checks=[]):
> > + if self._base.yum_cli_commands is None:
> > + raise Errors.ConfigError('registration of commands not
>
> supported')
>
> > +
> > + if 'command' in self._base.yum_cli_commands:
> > + raise Errors.ConfigError('Command "%s" already defined'
>
> % command)
>
> That last condition should be "if command" not "if 'command'" and
Oops, you're right.
> using has_key() is probably clearer.
OK. I'm still learning Python. This is my first try at Python programming :-)
>
> Apart from the above I'm happy with your patch.
>
Thanks for the feedback.
Now that I thought about it a bit more, wouldn't it be cleaner to have each
command implemented in a YumCommand object? Then yum_cli_commands would
become a dictionary mapping name to a YumCommand object.
YumCommand would implement
getNames() multiple names for command aliasing
doChecks(cli) called from cli.parseArguments() or doCommand()
doCommand(cli) the actual command handler
getUsage() short usage description
Cheersm
Bastiaan
> Menno
>
> _______________________________________________
> Yum-devel mailing list
> Yum-devel at linux.duke.edu
> https://lists.dulug.duke.edu/mailman/listinfo/yum-devel
More information about the Yum-devel
mailing list