[Yum-devel] [PATCH]: allow plugins to add new commands to the cli

Bastiaan Bakker bastiaan.bakker at enovation.nl
Tue Sep 12 23:11:52 UTC 2006


On Tuesday 12 September 2006 23:00, Bastiaan Bakker wrote:
---8<--
> 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
>

I've attached an updated patch that uses the YumCommand object approach. The 
result may be a bit more verbose, but looks a lot cleaner IMHO.

A plugin would use it like this:

class FooBarCommand(cli.YumCommand):
    def getNames(self):
        return ['foobar', 'foo-bar']

    def doCheck(self, base):
        cli.checkRootUID(base)

    def doCommand(self, base):
        return 0, ['nothing to do for foobar']
    
def config_hook(conduit):
    conduit.registerCommand(FooBarCommand())

Cheers,

Bastiaan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: yum-enable-command-extentions-v2.patch
Type: text/x-diff
Size: 27753 bytes
Desc: not available
Url : http://lists.baseurl.org/pipermail/yum-devel/attachments/20060913/4cf65298/attachment.bin 


More information about the Yum-devel mailing list