Skip to content

Commit

Permalink
Allow overriding default configuration file path via a command line f…
Browse files Browse the repository at this point in the history
…lag (#42)

* allow overriding default config file path via flag

* update comment
  • Loading branch information
utkuufuk committed Sep 23, 2021
1 parent 679c90a commit f370e34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ Run this as a cron job to periodically check custom data sources and automatical
An example use case could be to create a Trello card for each GitHub issue that's been assigned to you.

## Configuration
Copy and rename `config.example.yml` as `config.yml`, then set your own values in `config.yml`. Most of the configuration parameters are self explanatory, so the following only covers some of them:
Copy and rename `config.example.yml` as `config.yml` (default), then set your own values in `config.yml`.

You can also use a non-default config file path using the `-c` flag:
```console
go run ./cmd/entrello -c /path/to/config/file
```

Most of the configuration parameters are self explanatory, so the following only covers the important ones:

### Global Timeout
You can edit the `timeout_secs` config value in order to update global timeout (in seconds) for a single execution.

The execution will not terminate until the timeout is reached, so it's important that the timeout is shorter than the cron job period.

### Trello
You need to set your [Trello API key & token](https://trello.com/app-key) in the configuraiton file, as well as the Trello board & list IDs.

The given list will be the one that new cards is going to be inserted, and it has to be in the given board.
You need to set your [Trello API key & token](https://trello.com/app-key) in the configuraiton file, as well as the Trello board ID.

### Telegram
You need a Telegram token & a chat ID in order to enable the integration if you want to receive messages on card updates & possible errors.
Expand All @@ -44,7 +49,7 @@ For instance, strict mode can be used to automatically remove resolved GitHub is
Each data source must have a distinct Trello label associated with it.

#### **`list_id`**
Each data source must have a target Trello list ID associated with it.
Each data source must have a target Trello list ID associated with it. The selected list must be in the same board as configured via the `board_id` parameter.

#### **`period`**
You can define a custom query period for each source, by populating the `type` and `interval` fields under the `period` for a source.
Expand Down Expand Up @@ -79,7 +84,7 @@ Both of the following jobs run every hour and both assume that `config.yml` is l
``` sh
# use "go run"
# 'config.yml' should be located in '/home/utku/git/entrello'
# your go executable may or may not be located in the same place (i.e. /usr/local/go/bin/)
# your go executable may or may not be located in the same location (i.e. /usr/local/go/bin/)
0 * * * * cd /home/utku/git/entrello && /usr/local/go/bin/go run ./cmd/entrello

# use binary executable
Expand Down
16 changes: 11 additions & 5 deletions cmd/entrello/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"flag"
"log"
"sync"
"time"
Expand All @@ -17,10 +18,15 @@ var (
)

func main() {
// read configuration file path
var configFile string
flag.StringVar(&configFile, "c", "config.yml", "config file path")
flag.Parse()

// read config params
cfg, err := config.ReadConfig("config.yml")
cfg, err := config.ReadConfig(configFile)
if err != nil {
log.Fatalf("Could not read config variables: %v", err)
log.Fatalf("Could not read configuration: %v", err)
}

// get a system logger instance
Expand All @@ -29,7 +35,7 @@ func main() {
// get current time for the configured location
loc, err := time.LoadLocation(cfg.TimezoneLocation)
if err != nil {
logger.Fatalf("invalid timezone location: %v", loc)
logger.Fatalf("Invalid timezone location: %v", loc)
}
now = time.Now().In(loc)

Expand All @@ -47,12 +53,12 @@ func main() {
// initialize the Trello client
client, err := trello.NewClient(cfg.Trello)
if err != nil {
logger.Fatalf("could not create trello client: %v", err)
logger.Fatalf("Could not create trello client: %v", err)
}

// load Trello cards from the board with relevant labels
if err := client.LoadBoard(labels); err != nil {
logger.Fatalf("could not load existing cards from the board: %v", err)
logger.Fatalf("Could not load existing cards from the board: %v", err)
}

// fetch new cards from each source and handle the new & stale ones
Expand Down

0 comments on commit f370e34

Please sign in to comment.