You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2018/02/02 12:08:09 UTC

[karaf] branch karaf-4.1.x updated: [KARAF-5568] support return codes in karaf commands

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.1.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.1.x by this push:
     new 36e1608  [KARAF-5568] support return codes in karaf commands
36e1608 is described below

commit 36e1608f48ca469f0f2ae6110ded14d1f1a96b99
Author: Johannes Utzig <j....@seeburger.de>
AuthorDate: Tue Jan 16 14:43:06 2018 +0100

    [KARAF-5568] support return codes in karaf commands
    
    if the return code of an Action is an integer it is
    
     * no longer printed
     * used as return code for an SSH shell
---
 .../java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java | 2 +-
 shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
index 1253967..e2f264f 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
@@ -367,7 +367,7 @@ public class ConsoleSessionImpl implements Session {
                 }
                 try {
                     Object result = session.execute(command);
-                    if (result != null) {
+                    if (result instanceof String) {
                         session.getConsole().println(session.format(result, Converter.INSPECT));
                     }
                 } catch (InterruptedException e) {
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
index 2b3d507..926916e 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
@@ -131,6 +131,11 @@ public class ShellCommand implements Command, Runnable, SessionAware {
                 }
                 if (result != null)
                 {
+                	if(result instanceof Integer) {
+                		// if it is an integer it's interpreted as a return code
+                		exitStatus = (Integer) result;
+                	}
+
                     // TODO: print the result of the command ?
 //                    session.getConsole().println(session.format(result, Converter.INSPECT));
                 }

-- 
To stop receiving notification emails like this one, please contact
jbonofre@apache.org.