~chrisppy/beagles

8fd3cd21ca2266a2d3a13a71d152349ffb13ec46 — Chris Palmer 1 year, 5 months ago 555e92e v0.1.1
Fix setting config and cache directories
5 files changed, 46 insertions(+), 22 deletions(-)

M CHANGELOG.md
M Makefile
M doc/beagles-config.5.scd
M doc/beagles.1.scd
M main.go
M CHANGELOG.md => CHANGELOG.md +5 -0
@@ 2,6 2,11 @@

## [Unreleased]

## [0.1.1] - 2020-07-27
### ~chrisppy
  - Change from config and database directories set at compile time, to use 
    default hardcoded folders with environment variable overrides

## [0.1.0] - 2020-07-27
### ~chrisppy
  - Implemented UI

M Makefile => Makefile +2 -10
@@ 4,15 4,12 @@

PKGNAME=beagles

VERSION=0.1.0
VERSION=0.1.1

VPATH=doc
PREFIX?=/usr/local
_INSTDIR=$(DESTDIR)$(PREFIX)
BINDIR=$(_INSTDIR)/bin
SHAREDIR?=$(HOME)/.local/share
CONFIGDIR?=$(HOME)/.config
CACHEDIR?=$(HOME)/.cache
MANDIR?=$(_INSTDIR)/share/man
GO?=go
GOFLAGS?=


@@ 21,13 18,8 @@ GOSRC!=find . -name '*.go'
GOSRC+=go.mod go.sum

beagles: $(GOSRC)
	mkdir -m755 -p $(SHAREDIR)/$(PKGNAME) $(CONFIGDIR)/$(PKGNAME) \
		$(CACHEDIR)/$(PKGNAME)
	$(GO) build $(GOFLAGS) \
		-ldflags "-X main.Version=$(VERSION)/$(PKGNAME) \
		-X main.ShareDir=$(SHAREDIR)/$(PKGNAME) \
		-X main.ConfigDir=$(CONFIGDIR)/$(PKGNAME) \
		-X main.CacheDir=$(CACHEDIR)/$(PKGNAME)" \
		-ldflags "-X main.Version=$(VERSION)/$(PKGNAME)" \
		-o $@

DOCS := \

M doc/beagles-config.5.scd => doc/beagles-config.5.scd +1 -1
@@ 107,6 107,6 @@ Colors can be specified either as W3C color names, RGB hexadecimal strings++

Written and maintained by Chris Palmer

beagles v0.1.0/beagles is available under the terms of the GPL-3.0 license.
beagles v0.1.1/beagles is available under the terms of the GPL-3.0 license.

Copyright © 2020  Chris Palmer <chris@red-oxide.org>

M doc/beagles.1.scd => doc/beagles.1.scd +8 -1
@@ 53,6 53,13 @@ beagles - TUI RSS feed aggregator
*quit, q*
	exit the application

# ENVIRONMENT

	The config and database directories default to $HOME/.config/beagles and
	$HOME/.cache/beagles, respectfully.  If you want to override these paths
	you must set the BEAGLES_CFG and BEAGLES_DB environment variables within
	your shell.

# CONFIGURATION

See *beagles-config*(5)


@@ 73,6 80,6 @@ https://sr.ht/~chrisppy/beagles

Written and maintained by Chris Palmer

beagles v0.1.0/beagles is available under the terms of the GPL-3.0 license.
beagles v0.1.1/beagles is available under the terms of the GPL-3.0 license.

Copyright © 2020  Chris Palmer <chris@red-oxide.org>

M main.go => main.go +30 -10
@@ 18,6 18,7 @@
package main

import (
	"os"
	"path/filepath"

	"git.sr.ht/~chrisppy/beagles/config"


@@ 29,25 30,44 @@ import (
var (
	// Version of the application
	Version string
)

	// ConfigDir is the path defined during build i.e. ~/.config/beagles
	ConfigDir string
func main() {
	configDir := os.Getenv("BEAGLES_CFG")
	if configDir == "" {
		d, err := os.UserConfigDir()
		if err != nil {
			wlog.Fatal(err.Error())
		}
		configDir = filepath.Join(d, "beagles")
	}

	// ShareDir is the path defined during build i.e. ~/usr/local/share/beagles
	// ShareDir string
	cacheDir := os.Getenv("BEAGLES_DB")
	if cacheDir == "" {
		d, err := os.UserCacheDir()
		if err != nil {
			wlog.Fatal(err.Error())
		}
		cacheDir = filepath.Join(d, "beagles")
	}

	// CacheDir is the path defined during build i.e. ~/.cache/beagles
	CacheDir string
)
	// TODO: Uncomment after podcast functionality is implemented
	// shareDir := os.Getenv("BEAGLES_DL")
	// if shareDir == "" {
	//	d, err := os.UserHomeDir()
	//	if err != nil {
	//		wlog.Fatal(err.Error())
	//	}
	//	shareDir = filepath.Join(d, ".local", "share", "beagles")
	// }

func main() {
	path := filepath.Clean(filepath.Join(CacheDir, "beagles.db"))
	path := filepath.Clean(filepath.Join(cacheDir, "beagles.db"))
	db, err := db.ReadDB(path)
	if err != nil {
		wlog.Fatal(err.Error())
	}

	cfg := config.Load(ConfigDir)
	cfg := config.Load(configDir)

	i := &ui.UI{
		Version: Version,