Hi, I would implement my own console commands but I'm not sure how to do it correctly. The command should print something on the console, so my first attempt was to simply return the String in my execute(...) method. This worked like a charm and I also could write Unit tests with assertions on the returned value.
But when I wrote integration tests according to http://iocanel.blogspot.de/2012/01/advanced-integration-testing-with-pax.html, I realized that the standard Karaf commands print their output on System.out and execute(...) returns null. If I implement both, the output appears on the console twice of course. I could rewrite my command implementation to use System.out, but then my Unit tests have also to be rewritten (temporarily redirect System.out to another PrintStream - IMHO not a nice workaround). Question: What is the purpose of the return value of org.apache.karaf.shell.commands.Action.execute(CommandSession)? Unfortunately it is not commented. Question: What is the correct way for own commands? Return the value or print on System.out? In my opinion it would be nicer if the commands simply return their value and the calling framework decides where to print it. Regards
