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 2014/07/19 14:41:56 UTC

git commit: [KARAF-3124] Add shell:env command

Repository: karaf
Updated Branches:
  refs/heads/master 096f14077 -> f7f396b6c


[KARAF-3124] Add shell:env command


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/f7f396b6
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/f7f396b6
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/f7f396b6

Branch: refs/heads/master
Commit: f7f396b6ce73884c9aa603cabbd0222341ce2cb7
Parents: 096f140
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Sat Jul 19 14:41:28 2014 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Sat Jul 19 14:41:28 2014 +0200

----------------------------------------------------------------------
 manual/src/main/webapp/users-guide/console.conf |  1 +
 .../karaf/shell/commands/impl/EnvAction.java    | 52 ++++++++++++++++++++
 .../services/org/apache/karaf/shell/commands    |  1 +
 3 files changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/f7f396b6/manual/src/main/webapp/users-guide/console.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/users-guide/console.conf b/manual/src/main/webapp/users-guide/console.conf
index bf09f7c..5191a5e 100644
--- a/manual/src/main/webapp/users-guide/console.conf
+++ b/manual/src/main/webapp/users-guide/console.conf
@@ -285,6 +285,7 @@ Karaf console provides some core commands similar to Unix environment:
 * {{shell:date}} displays the current date (optionally using a format)
 * {{shell:watch}} periodically executes a command and refresh the output
 * {{shell:each}} executes a closure on a list of arguments
+* {{shell:env}} displays or sets the value of a shell session variable
 * {{shell:more}} is a file pager
 * {{shell:wc}} prints newline, words, and byte counts for each file
 * {{shell:echo}} echoes and prints arguments to stdout

http://git-wip-us.apache.org/repos/asf/karaf/blob/f7f396b6/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java
new file mode 100644
index 0000000..006efb5
--- /dev/null
+++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/impl/EnvAction.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.shell.commands.impl;
+
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Session;
+
+/**
+ * Command to get the value of a session variable.
+ */
+@Command(scope = "shell", name = "env", description = "Get/set the value of a console session variable.")
+@Service
+public class EnvAction implements Action {
+
+    @Argument(index = 0, name = "variable", description = "The name of the console session variable.", required = true, multiValued = false)
+    String variable;
+
+    @Argument(index = 1, name = "value", description = "The new value of the console session variable.", required = false, multiValued = false)
+    String value;
+
+    @Reference
+    Session session;
+
+    @Override
+    public Object execute() throws Exception {
+        if (value == null) {
+            System.out.println(session.get(variable));
+        } else {
+            session.put(variable, value);
+        }
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/f7f396b6/shell/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
----------------------------------------------------------------------
diff --git a/shell/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands b/shell/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
index 8149c3d..25b46f1 100644
--- a/shell/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
+++ b/shell/commands/src/main/resources/META-INF/services/org/apache/karaf/shell/commands
@@ -23,6 +23,7 @@ org.apache.karaf.shell.commands.impl.DateAction
 org.apache.karaf.shell.commands.impl.EachAction
 org.apache.karaf.shell.commands.impl.EchoAction
 org.apache.karaf.shell.commands.impl.EditAction
+org.apache.karaf.shell.commands.impl.EnvAction
 org.apache.karaf.shell.commands.impl.ExecuteAction
 org.apache.karaf.shell.commands.impl.GrepAction
 org.apache.karaf.shell.commands.impl.HeadAction