Skip to content

Commit

Permalink
Get configuration file from ~/.config/emissary.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
dubsec committed Feb 11, 2020
1 parent 05009b7 commit 46cc8fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Examples:
cat domins.txt | emissary --slack --stdin
```

**Create emissary.ini in the same location as the executable:**
**Create ~/.config/emissary.ini with the following:**
```
[Telegram]
chat_id=xxxxxx
Expand Down Expand Up @@ -72,7 +72,7 @@ Some stuff that I plan to implement:
- [ ] Discord
- [X] Email
- [ ] Let user decide max rows to be sent
- [ ] Place config file in ~/.config/emissary.ini
- [X] Place config file in ~/.config/emissary.ini

## Contributing
Any feedback or ideas are welcome! Want to improve something? Create a pull request!
Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"log"
"net/http"
"os"
"os/user"
"path/filepath"
"strings"

"gopkg.in/ini.v1"
Expand Down Expand Up @@ -44,7 +46,15 @@ func main() {
os.Exit(0)
}

cfg, err := ini.Load("emissary.ini")
User, err := user.Current()

if err != nil {
log.Fatal("Something went wrong trying to figure out your home directory", err)
}

configPath := filepath.FromSlash(User.HomeDir + "/.config/emissary.ini")

cfg, err := ini.Load(configPath)
if err != nil {
log.Fatal("Fail to read configuration file: ", err)
os.Exit(1)
Expand Down

0 comments on commit 46cc8fc

Please sign in to comment.