[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/a7738ff4 Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a7738ff4 Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a7738ff4 Branch: refs/heads/karaf-2.3.x Commit: a7738ff4e3b6d56f436be987df0407825f7214a0 Parents: 986fc96 Author: Jean-Baptiste Onofré <jbono...@apache.org> Authored: Sat Jul 19 17:47:32 2014 +0200 Committer: Jean-Baptiste Onofré <jbono...@apache.org> Committed: Sat Jul 19 17:47:32 2014 +0200 ---------------------------------------------------------------------- .../apache/karaf/shell/commands/EnvAction.java | 44 ++++++++++++++++++++ .../services/org/apache/karaf/shell/commands | 1 + .../OSGI-INF/blueprint/shell-commands.xml | 3 ++ 3 files changed, 48 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/a7738ff4/shell/commands/src/main/java/org/apache/karaf/shell/commands/EnvAction.java ---------------------------------------------------------------------- diff --git a/shell/commands/src/main/java/org/apache/karaf/shell/commands/EnvAction.java b/shell/commands/src/main/java/org/apache/karaf/shell/commands/EnvAction.java new file mode 100644 index 0000000..c692292 --- /dev/null +++ b/shell/commands/src/main/java/org/apache/karaf/shell/commands/EnvAction.java @@ -0,0 +1,44 @@ +/* + * 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; + +import org.apache.felix.gogo.commands.Argument; +import org.apache.felix.gogo.commands.Command; +import org.apache.karaf.shell.console.AbstractAction; + +/** + * Command to get/set the value of a session variable. + */ +@Command(scope = "shell", name = "env", description = "Get/set the value of a console session variable.") +public class EnvAction extends AbstractAction { + + @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; + + protected Object doExecute() 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/a7738ff4/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 7344f22..85a9031 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 @@ -20,6 +20,7 @@ org.apache.karaf.shell.commands.ClearAction org.apache.karaf.shell.commands.DateAction org.apache.karaf.shell.commands.EachAction org.apache.karaf.shell.commands.EchoAction +org.apache.karaf.shell.commands.EnvAction org.apache.karaf.shell.commands.ExecuteAction org.apache.karaf.shell.commands.GrepAction org.apache.karaf.shell.commands.HistoryAction http://git-wip-us.apache.org/repos/asf/karaf/blob/a7738ff4/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml ---------------------------------------------------------------------- diff --git a/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml b/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml index 5f0242e..206ef14 100644 --- a/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml +++ b/shell/commands/src/main/resources/OSGI-INF/blueprint/shell-commands.xml @@ -38,6 +38,9 @@ <command name="shell/echo"> <action class="org.apache.karaf.shell.commands.EchoAction"/> </command> + <command name="shell/env"> + <action class="org.apache.karaf.shell.commands.EnvAction"/> + </command> <command name="shell/exec"> <action class="org.apache.karaf.shell.commands.ExecuteAction"/> </command>