Skip to content

Commit

Permalink
docs: fix generate docs and expand on getting started (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Jan 12, 2021
1 parent 91cd790 commit 4034690
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 16 deletions.
20 changes: 20 additions & 0 deletions docs/generators/basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Basic generator

The basic generator looks at the `key:""`, `desc:""` and `default:""` tags on service configuration structs and uses them to ask the user to fill in their corresponding values.

Example:
```shell
$ shoutrrr generate telegram
```
```yaml
Generating URL for telegram using basic generator
Enter the configuration values as prompted

Token: 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
Preview[Yes]: No
Notification[Yes]:
ParseMode[None]:
Channels: @mychannel

URL: telegram://110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw@telegram?channels=@mychannel&notification=Yes&parsemode=None&preview=No
```
10 changes: 10 additions & 0 deletions docs/generators/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generators

Generators are used to create service configurations via the command line.
The main generator is the reflection based [Basic generator](./basic) that aims to be able to generator configurations for all the core services via a set of simple questions.

## Usage

```bash
$ shoutrrr generate [OPTIONS] -g <GENERATOR> <SERVICE>
```
64 changes: 48 additions & 16 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,51 @@
Using shoutrrr is easy! There is currently two ways of using it as a package.

### Using the direct send command
Easiest to use, but very limited.

```go
url := "slack://token-a/token-b/token-c"
err := shoutrrr.Send(url, "Hello world (or slack channel) !")
url := "slack://token-a/token-b/token-c"
err := shoutrrr.Send(url, "Hello world (or slack channel) !")
```

### Using a sender
Using a sender gives you the ability to preconfigure multiple notification services and send to all of them with the same `Send(message, params)` method.

```go
url := "slack://token-a/token-b/token-c"
sender, err := shoutrrr.CreateSender(url)
sender.Send("Hello world (or slack channel) !", map[string]string { /* ... */ })
urlA := "slack://token-a/token-b/token-c"
urlB := "telegram://110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw@telegram?channels=@mychannel"
sender, err := shoutrrr.CreateSender(urlA, urlB)

// Send notifications instantly to all services
sender.Send("Hello world (or slack/telegram channel)!", map[string]string { "title": "He-hey~!" })

// ...or bundle notifications...
func doWork() error {
// ...and send them when leaving the scope
defer sender.Flush(map[string]string { "title": "Work Result" })

sender.Enqueue("Started doing %v", stuff)

// Maybe get creative...?
defer func(start time.Time) {
sender.Enqueue("Elapsed: %v", time.Now().Sub(start))
}(time.Now())

if err := doMoreWork(); err != nil {
sender.Enqueue("Oh no! %v", err)

// This will send the currently queued up messages...
return
}

sender.Enqueue("Everything went very well!")

// ...or this:
}

```


## Through the CLI

Start by running the `build.sh` script.
Expand Down Expand Up @@ -58,10 +89,19 @@ $ shoutrrr verify \
Generate and display the configuration for a notification service url.

```bash
$ shoutrrr generate \
--url "<SERVICE_URL>"
$ shoutrrr generate [OPTIONS] <SERVICE>
```

| Flags | Description |
| ---------------------------- | ------------------------------------------------|
| `-g, --generator string` | The generator to use (default "basic") |
| `-p, --property stringArray` | Configuration property in key=value format |
| `-s, --service string` | The notification service to generate a URL for |

**Note**: Service can either be supplied as the first argument or using the `-s` flag.

For more information on generators, see [Generators](./generators/overview.md).

### Options

#### Debug
Expand All @@ -78,12 +118,4 @@ The target url for the notifications generated, see [overview](./services/overvi

| Flags | Env. | Default | Required |
| ------------- | -------------- | ------- | -------- |
| `--url`, `-u` | `SHOUTRRR_URL` | N/A ||

### Action details

```shell
$ ./shoutrrr generate
Usage:
./shoutrrr generate [OPTIONS] <service>
```
| `--url`, `-u` | `SHOUTRRR_URL` | N/A ||

0 comments on commit 4034690

Please sign in to comment.