Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Mar 9, 2020
1 parent 86c9280 commit 5b71f0d
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 18 deletions.
102 changes: 102 additions & 0 deletions docs/extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
layout: page
title: Extensions
permalink: /extensions/
---

RD can use *extension jars* to add additional functionality.

## Using Extensions

Download an extension jar, and place it in the `RD_EXT_DIR` directory.

By default for UNIX this is located at `~/.rd/ext`, you can overridde the location in your `~/.rd/rd.conf` file by adding:

``` sh
export RD_EXT_DIR=/my/ext/dir
```

When you run `rd`, the extensions will be loaded and added as commands in the hierarchy of available subcommands.

You can check the list of loaded extensions by running `rd` with `RD_DEBUG=1`.

## Develop an Extension

Extensions can be developed as Java libraries.

### Dependencies

Add the `rd-cli-lib` dependency to your project.

Available in Jcenter repo or [Bintray](https://bintray.com/rundeck/maven/rd-cli-lib).

### Gradle example

A demo project can be seen here: <https://github.com/gschueler/rd-extension-demo>

~~~{groovy}
//use bintray maven repo
repositories {
//available in jcenter
jcenter()
//or directly from bintray
maven {
url "https://rundeck.bintray.com/maven"
}
}
dependencies {
api "org.rundeck.cli:rd-cli-lib:{{site.app_version}}"
api "org.rundeck.cli-toolbelt:toolbelt-jewelcli:0.2.11"
implementation "org.rundeck.api:rd-api-client:{{site.app_version}}"
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:converter-jackson:2.7.1'
implementation 'com.squareup.retrofit2:converter-simplexml:2.7.1'
}
~~~

## Implement `RdCommandExtension`

The following example adds the command `rd sub path somecomand`.

```java
package com.mycompany;
import org.rundeck.client.tool.extension.RdCommandExtension;
import org.rundeck.client.tool.extension.RdTool;
import org.rundeck.client.util.Client;
import org.rundeck.client.util.ServiceClient;
import org.rundeck.toolbelt.Command;
import org.rundeck.toolbelt.CommandOutput;
import org.rundeck.toolbelt.SubCommand;

@SubCommand(path={"sub","path"})
class MyClass implements RdCommandExtension{
RdTool rdTool;
public void setRdTool(RdTool rdTool){
this.rdTool=rdTool;
}

@Command
public boolean someCommand(CommandOutput out){
out.output("running someCommand");
}
}
```

Argument parsing is done with the CLI Toolbelt, and can use the JewelCLI library. See the Example code.

## Declare the Service

The `rd` tool uses the Java ServiceLoader to load extensions on the classpath.

Declare your class in a file called `META-INF/services/org.rundeck.client.tool.extension.RdCommandExtension`

com.mycompany.MyClass

For a standard Gradle java library, create the file in `src/main/resources/META-INF/services/org.rundeck.client.tool.extension.RdCommandExtension`

## Javadoc

(to be published)
11 changes: 7 additions & 4 deletions docs/javalib.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ The Java library used by RD can be used as a dependency in your Java project to

Currently the library is published to Bintray (jcenter/maven central TBD).

See: <https://bintray.com/rundeck/rundeck-maven/rd-api-client>
See: <https://bintray.com/rundeck/maven/rd-api-client>

## Gradle usage

A demo project can be seen here: <https://github.com/gschueler/rd-api-demo>

~~~{groovy}
//use bintray maven repo
repositories {
repositories {
//available in jcenter
jcenter()
//or directly from bintray
maven {
url "https://rundeck.bintray.com/rundeck-maven"
url "https://rundeck.bintray.com/maven"
}
}
Expand All @@ -31,4 +34,4 @@ dependencies {

## Javadoc

(to be published)
(to be published)
20 changes: 6 additions & 14 deletions rd-cli-tool/src/main/resources/rd-banner.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@

- ${red}RD$$ - Rundeck API Client Tool (v1.2.2) - ${cyan}https://rundeck.github.io/rundeck-cli/$$

${red}
.:'/*/'`:,·:~·–:., ,._., ._
/::/:/:::/:::;::::::/`':.,' /::::::::::'/:/:~-.,
/·*'`·´¯'`^·-~·:–-'::;:::'`; /:-·:;:-·~·';/:::::::::`·-.
'\ '`;::'i‘ '; '`~-:;:::::::::'`,
'`; ,– ., 'i:'/ ',. '`·-:;:::::'i'‘
i i':/:::'; ;/' `'i ,_ '`;:::'¦‘
i i/:·'´ ,:'' 'i ;::/`:, i'::/
'; ' ,:, ~;'´:::'`:, _; ;:/;;;;:'; ¦'/
'i i:/\ `;::::/:'`;' /::'; ,':/::::::;' ,´
; ;/ \ '`:/::::/',/-:;_i ,'/::::;·´ ,'´
'; ,' \ '`;/' '`·. `'¯¯ ' , ·'´
`'*´ '`~·-·^'´ `' ~·- .,. -·~ ´
'$$
________________
___ __ \__ __ \
__ /_/ /_ / / /
_ _, _/_ /_/ /
/_/ |_| /_____/
$$

0 comments on commit 5b71f0d

Please sign in to comment.