Search code examples
apache-karafkaraf

Can you override the help option of an Apache Karaf command?


Is there anyway in Apache Karaf 3.0.x to override the default help message that's displayed when you type --help?

I've browsed the documentation and couldn't find anything. I've looked through the source code and found in DefaultActionPreparator.prepare() it checks for the --help string in the parameters and if it's there it runs a printUsage() function from the ActionMetaData class. The problem is that I don't see any easy way to override that. It looks like in Karaf 4.0.x or maybe 5 things are getting refactored to make it easier to override the help functionality, but I'm currently using 3.0.4 and can't upgrade to an experimental version in my production systems.

So, does anyone know if it's possible to override the help message for a command and if so do you know of some documentation?


Solution

  • It's not possible to override the default help, but you can add your own help on your own commands by adding a bundle.info file in OSGI-INF which uses a simple markup for help

    For example:

    h1. Synopsis
    
        ${project.name}
    
        ${project.description}
    
        Maven URL:
            \u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
    
    h1. Description
    
        This bundle provides the Karaf shell commands to manipulate DS Components.
    
    h1. Commands
    
        The following commands are available:
    \${command-list|scr|indent=8,list,cyan}
    
    h1. See also
    
        \u001B[36mCommands\u001B[0m and \u001B[36mDeclarative Services\u001B[0m sections of the Karaf User Guide.
    

    or here https://github.com/apache/karaf/blob/master/scr/command/src/main/resources/OSGI-INF/bundle.info

    EDIT:
    The only thing that comes to my mind to "Patch" an existing help might be with a fragment bundle which attaches to the bundle to change the help in. With luck the classloader will rather load the help from the fragment instead of the host-bundle. This used to also work to "patch" the manifest so why not for this.