Skip to content

Commit

Permalink
Formalize add/remove examples as bashbot commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mathew-fleisch committed Aug 22, 2021
1 parent 166d573 commit 0c8c1a9
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 23 deletions.
46 changes: 23 additions & 23 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Example Bashbot Commands

This directory contains a few sample Bashbot commands that can be applied to a configuration json by executing a helper script or by copy/pasting the json directly. Each example (directory) also contains a read-me file describing usage information. The [add-command.sh](add-command.sh) script expects the environment variable `BASH_CONFIG_FILEPATH` to be set and takes one argument (filepath of the command to add to the configuration json). The [remove-command.sh](remove-command.sh) script also expects the environment variable `BASH_CONFIG_FILEPATH` to be set and takes one argument (the value of the parameter `trigger` within the specific command).
This directory contains a few sample Bashbot commands that can be applied to a configuration json by executing a helper script or by copy/pasting the json directly. Each example (directory) also contains a read-me file describing usage information. The [add-example/add-command.sh](add-example/add-command.sh) script expects the environment variable `BASH_CONFIG_FILEPATH` to be set and takes one argument (filepath of the command to add to the configuration json). The [remove-example/remove-command.sh](remove-example/remove-command.sh) script also expects the environment variable `BASH_CONFIG_FILEPATH` to be set and takes one argument (the value of the parameter `trigger` within the specific command).


```bash
# From Bashbot source root
export BASHBOT_CONFIG_FILEPATH=${PWD}/config.json

./examples/add-command.sh examples/version/version.json
./add-example/add-command.sh version/version.json
# version added to /Users/user/bashbot/config.json

./examples/add-command.sh examples/version/version.json
./add-example/add-command.sh version/version.json
# Trigger already exists: version

./examples/remove-command.sh version
./remove-example/remove-command.sh version
# version removed from /Users/user/bashbot/config.json

./examples/remove-command.sh version
./remove-example/remove-command.sh version
# Trigger not found to remove: version
```

Expand All @@ -25,36 +25,36 @@ export BASHBOT_CONFIG_FILEPATH=${PWD}/config.json

1. Simple call/response
- [Ping/Pong](ping)
- \+ `./add-command.sh ping/ping.json`
- \- `./remove-command.sh ping`
- \+ `./add-example/add-command.sh ping/ping.json`
- \- `./remove-example/remove-command.sh ping`
2. Run bash script
- [Get Caller Information](info)
- \+ `./add-command.sh info/info.json`
- \- `./remove-command.sh info`
- \+ `./add-example/add-command.sh info/info.json`
- \- `./remove-example/remove-command.sh info`
- [Get asdf Plugins](asdf)
- \+ `./add-command.sh asdf/asdf.json`
- \- `./remove-command.sh asdf`
- \+ `./add-example/add-command.sh asdf/asdf.json`
- \- `./remove-example/remove-command.sh asdf`
3. Run golang script
- [Get Running Version](version)
- \+ `./add-command.sh version/version.json`
- \- `./remove-command.sh version`
- \+ `./add-example/add-command.sh version/version.json`
- \- `./remove-example/remove-command.sh version`
4. Parse json via jq
- [List Available Commands](list)
- \+ `./add-command.sh list/list.json`
- \- `./remove-command.sh list`
- \+ `./add-example/add-command.sh list/list.json`
- \- `./remove-example/remove-command.sh list`
- [Describe Command](describe)
- \+ `./add-command.sh describe/describe.json`
- \- `./remove-command.sh describe`
- \+ `./add-example/add-command.sh describe/describe.json`
- \- `./remove-example/remove-command.sh describe`
5. Curl/wget
- [Get Latest Bashbot Release](latest-release)
- \+ `./add-command.sh latest-release/latest-release.json`
- \- `./remove-command.sh latest-release`
- \+ `./add-example/add-command.sh latest-release/latest-release.json`
- \- `./remove-example/remove-command.sh latest-release`
- [Get File From Repository](get-file-from-repo)
- \+ `./add-command.sh get-file-from-repo/get-config.json`
- \- `./remove-command.sh get-config`
- \+ `./add-example/add-command.sh get-file-from-repo/get-config.json`
- \- `./remove-example/remove-command.sh get-config`
- [Trigger Github Action](github-action)
- \+ `./add-command.sh github-action/trigger-github-action.json`
- \- `./remove-command.sh trigger-github-action`
- \+ `./add-example/add-command.sh github-action/trigger-github-action.json`
- \- `./remove-example/remove-command.sh trigger-github-action`



Expand Down
34 changes: 34 additions & 0 deletions examples/add-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Bashbot Example - Add Example Command

In this example, a json example can be added to a running configuration json.

***Note: This will not work when the configuration json is mounted as a configmap. Use the seed method if bashbot is deployed in kubernetes to use this example***

## Bashbot Configuration

This command is triggered by sending `bashbot asdf` in a slack channel where Bashbot is also a member. There is no external script for this command, takes no arugments/parameters, and expects Bashbot's examples directory to exist. The valid arguments for this command come from the output of `bashbot list-examples`

```json
{
"name": "Add Example Command",
"description": "Add command from Bashbot example commands",
"help": "bashbot add-example",
"trigger": "add-example",
"location": "./examples",
"command": ["./add-example/add-command.sh $(find . -name \"${add_command}.json\")"],
"parameters": [
{
"name": "add_command",
"allowed": [],
"description": "a command to add to bashbot config ('bashbot list-examples')",
"source": ["find . -name \"*.json\" | xargs -I {} basename {} .json"]
}
],
"log": false,
"ephemeral": false,
"response": "code",
"permissions": [
"all"
]
}
```
File renamed without changes.
22 changes: 22 additions & 0 deletions examples/add-example/add-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Add Example Command",
"description": "Add command from Bashbot example commands",
"help": "bashbot add-example",
"trigger": "add-example",
"location": "./examples",
"command": ["./add-example/add-command.sh $(find . -name \"${add_command}.json\")"],
"parameters": [
{
"name": "add_command",
"allowed": [],
"description": "a command to add to bashbot config ('bashbot list-examples')",
"source": ["find . -name \"*.json\" | xargs -I {} basename {} .json"]
}
],
"log": false,
"ephemeral": false,
"response": "code",
"permissions": [
"all"
]
}
29 changes: 29 additions & 0 deletions examples/list-examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Bashbot Example - Add Example Command

In this example, a json example can be added to a running configuration json.

***Note: This will not work when the configuration json is mounted as a configmap. Use the seed method if bashbot is deployed in kubernetes to use this example***

## Bashbot Configuration

This command is triggered by sending `bashbot asdf` in a slack channel where Bashbot is also a member. There is no external script for this command, takes no arugments/parameters, and expects Bashbot's examples directory to exist. This command takes no arguments.

```json
{
"name": "List Example Commands",
"description": "List commands from bashbot example commands",
"help": "bashbot list-examples",
"trigger": "list-examples",
"location": "./examples",
"command": [
"find . -name \"*.json\" | xargs -I {} basename {} .json"
],
"parameters": [],
"log": false,
"ephemeral": false,
"response": "code",
"permissions": [
"all"
]
}
```
22 changes: 22 additions & 0 deletions examples/list-examples/add-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Add Example Command",
"description": "Add command from Bashbot example commands",
"help": "bashbot add-example",
"trigger": "add-example",
"location": "./examples",
"command": ["./add-example/add-command.sh $(find . -name \"${add_command}.json\")"],
"parameters": [
{
"name": "add_command",
"allowed": [],
"description": "a command to add to bashbot config ('bashbot list-examples')",
"source": ["find . -name \"*.json\" | xargs -I {} basename {} .json"]
}
],
"log": false,
"ephemeral": false,
"response": "code",
"permissions": [
"all"
]
}
35 changes: 35 additions & 0 deletions examples/remove-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Bashbot Example - Remove Example Command

In this example, a json example can be removed from a running configuration.

***Note: This will not work when the configuration json is mounted as a configmap. Use the seed method if bashbot is deployed in kubernetes to use this example***

## Bashbot Configuration

This command is triggered by sending `bashbot asdf` in a slack channel where Bashbot is also a member. There is no external script for this command, takes no arugments/parameters, and expects Bashbot's examples directory to exist. The valid arguments for this command come from the output of `bashbot list-examples`

```json
{
"name": "Remove Example Command",
"description": "Remove command from bashbot example commands",
"help": "bashbot remove-example",
"trigger": "remove-example",
"location": "./examples",
"command": ["./remove-command.sh ${remove_command}"
],
"parameters": [
{
"name": "remove_command",
"allowed": [],
"description": "a command to remove to bashbot config ('bashbot list-examples')",
"source": ["find . -name \"*.json\" | xargs -I {} basename {} .json"]
}
],
"log": false,
"ephemeral": false,
"response": "code",
"permissions": [
"all"
]
}
```
File renamed without changes.
23 changes: 23 additions & 0 deletions examples/remove-example/remove-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Remove Example Command",
"description": "Remove command from bashbot example commands",
"help": "bashbot remove-example",
"trigger": "remove-example",
"location": "./examples",
"command": ["./remove-command.sh ${remove_command}"
],
"parameters": [
{
"name": "remove_command",
"allowed": [],
"description": "a command to remove to bashbot config ('bashbot list-examples')",
"source": ["find . -name \"*.json\" | xargs -I {} basename {} .json"]
}
],
"log": false,
"ephemeral": false,
"response": "code",
"permissions": [
"all"
]
}

0 comments on commit 0c8c1a9

Please sign in to comment.