~chrisppy/beagles

0ef7727f984cfc303652417ec35ed325e4e6a6f8 — Chris Palmer 1 year, 27 days ago 3fa6667
Added stub for restore and updated manpage
3 files changed, 90 insertions(+), 12 deletions(-)

M db/db.go
M doc/beagles.1.scd
M main.go
M db/db.go => db/db.go +6 -0
@@ 232,6 232,12 @@ func (s *Storage) Backup(path string) error {
	return barefeed.WriteFile(m, path)
}

// Restore will clear the database and restore using a barefeed file
func (s *Storage) Restore(path string) error {
	// TODOL Implement me.
	return fmt.Errorf("restore is not yet implemented")
}

// CreateFeed will collect the rss feed and process through the elements
// and add the relevant data elements to the database
func (s *Storage) CreateFeed(url string) (Items, error) {

M doc/beagles.1.scd => doc/beagles.1.scd +22 -1
@@ 6,7 6,7 @@ beagles - TUI RSS feed aggregator

# SYNOPSIS

*beagles* [POSIX style options] ...
*beagles* [POSIX style options] [command] ...

# DESCRIPTION



@@ 25,6 25,9 @@ or even play the podcasts available on the feed.
*-D*
	Print debug lines.

*-f [file]*
	Set the file used to import or restore.

*-g [directory]*
	Set the directory for your gemini known_hosts.  If not set, use++
*XDG_DATA_HOME*/gemini.


@@ 35,12 38,30 @@ or even play the podcasts available on the feed.
*-l [directory]*
	Set the logging directory.  If not set, use *XDG_CACHE_HOME*/beagles.

*-p [directory]*
	Set the directory to use for export or backup.

*-s [directory]*
	Set the download directory. If not set use *XDG_DATA_HOME*/beagles.

*-V*
	Print version information

# COMMANDS

*import*
	Import feeds from an OPML file.  Must be used with the *-f* option.

*export*
	Export feeds to an OPML file.  Must be used with the *-p* option.

*backup*
	Backup all feed details to a barefeed file.  Must be used with the++
*-p* option.

*restore*
	Restore feed details from a barefeed file.  Must be used with the++
*-f* option.  *Note this will replace all data*.

# USAGE


M main.go => main.go +62 -11
@@ 18,10 18,12 @@
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"path/filepath"
	"strings"

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


@@ 40,7 42,7 @@ var (

func main() {

	opts, optind, err := getopt.Getopts(os.Args, "c:d:Df:g:hl:s:V")
	opts, optind, err := getopt.Getopts(os.Args, "c:d:Df:g:hl:p:s:V")
	if err != nil {
		if _, err := fmt.Fprintln(os.Stderr, err); err != nil {
			panic(fmt.Sprintf("error writing to stderr: %e\n", err))


@@ 48,7 50,7 @@ func main() {
		os.Exit(1)
	}

	var configDir, dbDir, dlDir, logDir, gmniDir, iopath string
	var configDir, dbDir, dlDir, logDir, gmniDir, ioPath, ioDir string
	debug := false
	for _, opt := range opts {
		switch opt.Option {


@@ 59,13 61,15 @@ func main() {
		case 'D':
			debug = true
		case 'f':
			iopath = opt.Value
			ioPath = opt.Value
		case 'g':
			gmniDir = opt.Value
		case 'h':
			printHelp()
		case 'l':
			logDir = opt.Value
		case 'p':
			ioDir = opt.Value
		case 's':
			dlDir = opt.Value
		case 'V':


@@ 122,34 126,81 @@ func main() {
			panic(fmt.Sprintf("error writing to stderr: %e\n", err))
		}
	} else if len(args) > 0 {
		if iopath == "" {
			if _, err := fmt.Fprintln(os.Stderr, `"-f path" is required to run a command`); err != nil {
				panic(fmt.Sprintf("error writing to stderr: %e\n", err))
			}
		}
		switch args[0] {
		case "import":
			if err := db.Import(iopath); err != nil {
			if ioPath == "" {
				if _, err := fmt.Fprintln(os.Stderr, `"-f file" is required for import`); err != nil {
					panic(fmt.Sprintf("error writing to stderr: %e\n", err))
				}
				os.Exit(1)
			}
			if err := db.Import(ioPath); err != nil {
				if _, err := fmt.Fprintln(os.Stderr, err); err != nil {
					panic(fmt.Sprintf("error writing to stderr: %e\n", err))
				}
				os.Exit(1)
			}
		case "export":
			if err := db.Export(iopath); err != nil {
			if ioDir == "" {
				if _, err := fmt.Fprintln(os.Stderr, `"-p directory" is required for export`); err != nil {
					panic(fmt.Sprintf("error writing to stderr: %e\n", err))
				}
				os.Exit(1)
			}
			if err := db.Export(ioDir); err != nil {
				if _, err := fmt.Fprintln(os.Stderr, err); err != nil {
					panic(fmt.Sprintf("error writing to stderr: %e\n", err))
				}
				os.Exit(1)
			}
		case "backup":
			if err := db.Backup(iopath); err != nil {
			if ioDir == "" {
				if _, err := fmt.Fprintln(os.Stderr, `"-p directory" is required for backup`); err != nil {
					panic(fmt.Sprintf("error writing to stderr: %e\n", err))
				}
				os.Exit(1)
			}
			if err := db.Backup(ioDir); err != nil {
				if _, err := fmt.Fprintln(os.Stderr, err); err != nil {
					panic(fmt.Sprintf("error writing to stderr: %e\n", err))
				}
				os.Exit(1)
			}
		case "restore":
			if ioPath == "" {
				if _, err := fmt.Fprintln(os.Stderr, `"-f file" is required for restore`); err != nil {
					panic(fmt.Sprintf("error writing to stderr: %e\n", err))
				}
				os.Exit(1)
			}

			reader := bufio.NewReader(os.Stdin)
		it:
			for {
				fmt.Println(`The will replace all data with the contents of the file!  Continue? [Y/n]`)

				input, err := reader.ReadString('\n')
				if err != nil {
					if _, err := fmt.Fprintln(os.Stderr, err); err != nil {
						panic(fmt.Sprintf("error writing to stderr: %e\n", err))
					}
				}

				switch strings.ToLower(strings.TrimSpace(input)) {
				case "n", "no":
					break it
				case "y", "yes":
					if err := db.Restore(ioPath); err != nil {
						if _, err := fmt.Fprintln(os.Stderr, err); err != nil {
							panic(fmt.Sprintf("error writing to stderr: %e\n", err))
						}
						os.Exit(1)
					}
					break it
				default:
					fmt.Println("Must be one of the following: Y/N, y/n, Yes/No, yes/no")
				}
			}
		default:
			if _, err := fmt.Fprintf(os.Stderr, "invalid command: %v\n", args); err != nil {
				panic(fmt.Sprintf("error writing to stderr: %e\n", err))