You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ro...@apache.org on 2018/10/01 23:14:15 UTC
svn commit: r1842572 -
/felix/site/trunk/content/documentation/subprojects/apache-felix-gogo/rfc-147-overview.mdtext
Author: rotty3000
Date: Mon Oct 1 23:14:14 2018
New Revision: 1842572
URL: http://svn.apache.org/viewvc?rev=1842572&view=rev
Log:
CMS commit to felix by rotty3000
Modified:
felix/site/trunk/content/documentation/subprojects/apache-felix-gogo/rfc-147-overview.mdtext
Modified: felix/site/trunk/content/documentation/subprojects/apache-felix-gogo/rfc-147-overview.mdtext
URL: http://svn.apache.org/viewvc/felix/site/trunk/content/documentation/subprojects/apache-felix-gogo/rfc-147-overview.mdtext?rev=1842572&r1=1842571&r2=1842572&view=diff
==============================================================================
--- felix/site/trunk/content/documentation/subprojects/apache-felix-gogo/rfc-147-overview.mdtext (original)
+++ felix/site/trunk/content/documentation/subprojects/apache-felix-gogo/rfc-147-overview.mdtext Mon Oct 1 23:14:14 2018
@@ -1,6 +1,5 @@
Title: RFC 147 Overview
-
The RFC-147 draft is not yet publicly available. It used to be called RFC-132, which can be found in an [early specification draft](http://www.osgi.org/download/osgi-4.2-early-draft.pdf)
This is an overview of its main features:
@@ -11,101 +10,105 @@ This is an overview of its main features
Commands are registered via service attributes, you don't have to register a specific service. This allows commands to be registered by existing services, just by adding the new attributes:
-{code:template=java}
+```java
Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put(CommandProcessor.COMMAND_SCOPE, "shell");
-dict.put(CommandProcessor.COMMAND_FUNCTION, new String[]({{ refs..path }}) {"sleep", "grep"});
+dict.put(CommandProcessor.COMMAND_FUNCTION, new String[] {"sleep", "grep"});
context.registerService(name, service, dict);
+```
+Scope is used to provide a namespace for commands. The commands above can be invoked as `shell:sleep` and `shell:grep`. If the scope is omitted (e.g. `sleep` and `grep`) then the first matching command is invoked.
+
+### Commands can have any signature
+
+Arguments are coerced to call the best matching method using reflection. A `CommandSession` argument is inserted if required:
+
+```java
+public void sleep(long millis) throws InterruptedException{
+ Thread.sleep(millis);
+}
- Scope is used to provide a namespace for commands. The commands above can be invoked as "shell:sleep" and "shell:grep". If the scope is omitted (e.g. "sleep" and "grep") then the first matching command is invoked.
-
- Commands can have any signature - arguments are coerced to call the best matching method using reflection. A {{CommandSession}} argument is inserted if required:
-
- {code:template=java}
- public void sleep(long millis) throws InterruptedException{
- Thread.sleep(millis);
- }
-
- public void sleep(String[] args) throws Exception;
+public void sleep(String[] args) throws Exception;
- public boolean grep(CommandSession session, String[] args) throws Exception;
-
+public boolean grep(CommandSession session, String[] args) throws Exception;
+```
The `CommandSession` interface provides methods for executing commands and getting and setting session variables:
-{code:template=java}
+```java
public interface org.apache.felix.service.command.CommandSession {
Object execute(CharSequence commandline) throws Exception;
Object get(String name);
void put(String name, Object value);
...
}
+```
-
- h2. Easy to use interactively - no unnecessary syntax.
-
- // simple command
-
- {noformat}
+### Easy to use interactively - no unnecessary syntax.
+
+- basic commands
+
+ ```shell
g! echo hello world
hello world
- {noformat}
-
- // session variables
-
- {noformat}
+ ```
+- session variables
+
+ ```shell
g! msg = "hello world"
g! echo $msg
hello world
- {noformat}
-
- // execution quotes () - similar to bash backquotes
-
- {noformat}
+ ```
+
+- execution quotes `()` - similar to bash backquotes
+
+ ```shell
g! (bundle 1) location
file:/Users/derek/Downloads/felix-framework-3.0.0/bundle/org.apache.felix.bundlerepository-1.6.2.jar
- {noformat}
-
- h2. Provides lists, pipes and closures.
-
- // lists - \[\]
-
- {noformat}
+ ```
+
+### Lists, maps, pipes and closures.
+
+- lists - `[]`
+
+ ```shell
g! list = [1 2 a b]
1
2
a
b
-
+ ```
+
+- maps - `[]`
+ ```shell
g! map = [Jan=1 Feb=2 Mar=3]
Jan 1
Feb 2
Mar 3
- {noformat}
-
- // pipes
-
- {noformat}
+ ```
+
+- pipes - `|`
+
+ ```shell
g! bundles | grep gogo
2|Active | 1|org.apache.felix.gogo.command (0.6.0)
3|Active | 1|org.apache.felix.gogo.runtime (0.6.0)
4|Active | 1|org.apache.felix.gogo.shell (0.6.0)
- {noformat}
-
- // closures - {}
-
- {noformat}
+ ```
+
+- closures - `{}`
+
+ ```shell
g! echo2 = { echo xxx $args yyy }
g! echo2 hello world
xxx hello world yyy
- {noformat}
-
- h2. Leverages existing Java capabilities, via reflection.
-
- // exception handling - console shows summary, but full context available
-
- {noformat}
+ ```
+
+### Leverages existing Java capabilities, via reflection.
+
+- exception handling - console shows summary, but full context available
+
+ ```shell
g! start xxx
E: Cannot coerce start[xxx] to any of [(Bundle)]
g! $exception printstacktrace
@@ -116,11 +119,11 @@ public interface org.apache.felix.servic
at org.apache.felix.gogo.runtime.shell.Closure.executeStatement(Closure.java:146)
at org.apache.felix.gogo.runtime.shell.Pipe.run(Pipe.java:91)
...
- {noformat}
-
- // add all public methods on java.lang.System as commands:
-
- {noformat}
+ ```
+
+- add all public methods on `java.lang.System` as commands:
+
+ ```shell
g! addcommand system (loadClass java.lang.System)
g! system:getproperties
sun.io.unicode.encodingUnicodeLittle
@@ -131,36 +134,35 @@ public interface org.apache.felix.servic
sun.os.patch.level unknown
os.version 10.6.2
[snip]
- {noformat}
-
- h2. Easy to implement and test commands without needing OSGi.
-
- Command implementations don't need to reference any OSGi interfaces. They can use System.in, System.out and System.err, just as you would in a trivial Java application. The ThreadIO service transparently manages the singleton System.out etc, so that each thread sees the appropriate stream:
-
- {code:template=java}public void cat(String[] args) throws Exception {
- for (String arg : args)
- IOUtil.copy(arg, System.out);
- }
+ ```
+### Easy to implement and test commands without needing OSGi.
+
+Command implementations don't need to reference any OSGi interfaces. They can use `System.in`, `System.out` and `System.err`, just as you would in a trivial Java application. The `ThreadIO` service transparently manages the singleton `System.out` etc, so that each thread sees the appropriate stream:
+```java
+public void cat(String[] args) throws Exception {
+ for (String arg : args) {
+ IOUtil.copy(arg, System.out);
+ }
+}
+```
## Normal commands can provide control primitives.
-{code:template=java}public void each(CommandSession session, Collection<Object> list, Function, closure) throws Exception {
+```java
+public void each(CommandSession session, Collection<Object> list, Function closure) throws Exception {
for (Object x : list) {
closure.execute(session, null);
}
}
+```
-
- {noformat}
- g! each [Jan Feb Mar] { echo $it | grep . }
- Jan
- Feb
- Mar
- {noformat}
-
- {note}
- The default *echo* command _returns_ a String and does not write to System.out. Also, by default, the console prints the results of each command, so *echo* appears to behave as you would expect.
- However, the console does not see the *each* closure above, so the result of echo would not be seen. This is why it is piped into *grep*, as the _result_ of the command as well as its output is written to a pipeline.
-
- {note}
+```shell
+g! each [Jan Feb Mar] { echo $it | grep . }
+Jan
+Feb
+Mar
+```
+
+**Note:** The default *echo* command _returns_ a String and does not write to System.out. Also, by default, the console prints the results of each command, so *echo* appears to behave as you would expect.
+However, the console does not see the *each* closure above, so the result of echo would not be seen. This is why it is piped into *grep*, as the _result_ of the command as well as its output is written to a pipeline.
\ No newline at end of file