Browse Source

Add creating a default config when no config is present

tags/v1.3.0
dtluna 8 months ago
parent
commit
46b89727c0
5 changed files with 35 additions and 8 deletions
  1. 3
    0
      commands/opml.go
  2. 16
    1
      config/config.go
  3. 1
    4
      go.mod
  4. 2
    0
      go.sum
  5. 13
    3
      main.go

+ 3
- 0
commands/opml.go View File

@@ -18,6 +18,9 @@ func ImportFromOPML(filenames []string, cfg *ini.File, configPath string) error
}
for _, outline := range OPML.Outlines() {
URL, err := config.ValidateURL(outline.XMLURL)
if err != nil {
return err
}
section, err := cfg.NewSection(URL.Hostname())
if err != nil {
return err

+ 16
- 1
config/config.go View File

@@ -14,6 +14,21 @@ type FeedEntry struct {
Name string
}

// CreateBlankConfigFile creates a blank config file with a helpful comment
func CreateBlankConfigFile(path string) error {
file := ini.Empty()
section, err := file.NewSection("dtluna")
if err != nil {
return err
}
section.Comment = "dtluna here is the name of the feed. These are default settings and you can delete them"
_, err = section.NewKey("url", "https://dtluna.net/index.xml")
if err != nil {
return err
}
return file.SaveTo(path)
}

// Parse the config. Returns an error if url in section is not a valid URL
func Parse(config *ini.File) ([]FeedEntry, error) {
entries := []FeedEntry{}
@@ -39,7 +54,7 @@ func Parse(config *ini.File) ([]FeedEntry, error) {
return entries, nil
}

func ValidateURL(str string)(*url.URL, error) {
func ValidateURL(str string) (*url.URL, error) {
URL, err := url.Parse(str)
if err != nil {
return nil, err

+ 1
- 4
go.mod View File

@@ -3,17 +3,14 @@ module git.dtluna.net/dtluna/gorgeous
require (
github.com/OpenPeeDeeP/xdg v0.2.0
github.com/PuerkitoBio/goquery v1.5.0 // indirect
github.com/Unknwon/com v0.0.0-20190214221849-2d12a219ccaf
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/forestgiant/sliceutil v0.0.0-20160425183142-94783f95db6c
github.com/gilliek/go-opml v1.0.0
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/hashicorp/errwrap v1.0.0
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/mmcdole/gofeed v1.0.0-beta2
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect
golang.org/x/text v0.3.0 // indirect

+ 2
- 0
go.sum View File

@@ -2,6 +2,8 @@ github.com/OpenPeeDeeP/xdg v0.2.0 h1:xr89rnllbkRkM7SV9Y++FJ8TGkbdkhhBQm5kOkGT7AE
github.com/OpenPeeDeeP/xdg v0.2.0/go.mod h1:tMoSueLQlMf0TCldjrJLNIjAc5qAOIcHt5REi88/Ygo=
github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP7EJk=
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
github.com/Unknwon/com v0.0.0-20190214221849-2d12a219ccaf h1:g3hliyjkDSCLzNlOEc6Bd1dngsiIwPb9LfPuYUv+F+Y=
github.com/Unknwon/com v0.0.0-20190214221849-2d12a219ccaf/go.mod h1:voKvFVpXBJxdIPeqjoJuLK+UVcRlo/JLjeToGxPYu68=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=

+ 13
- 3
main.go View File

@@ -4,8 +4,10 @@ import (
"git.dtluna.net/dtluna/gorgeous/commands"
"git.dtluna.net/dtluna/gorgeous/config"
"github.com/OpenPeeDeeP/xdg"
"github.com/Unknwon/com"
"gopkg.in/alecthomas/kingpin.v2"
ini "gopkg.in/ini.v1"
"gopkg.in/ini.v1"
"log"
"os"
"path"
"strconv"
@@ -13,7 +15,7 @@ import (

const (
appName = "gorgeous"
version = "1.2.1"
version = "1.3.0"
)

func feedValueIsURL(feed string) bool {
@@ -25,11 +27,19 @@ func feedValueIsURL(feed string) bool {

func main() {
x := xdg.New("", appName)
defaultConfigPath := path.Join(x.ConfigHome(), "config.ini")
if !com.IsExist(defaultConfigPath) {
err := config.CreateBlankConfigFile(defaultConfigPath)
if err != nil {
log.Fatal(err)
}
}

app := kingpin.New(appName, "CLI RSS feed reader")
app.Version(version)
configPath := app.Flag(
"config", "Set location of the config file with feed URLs.",
).Short('c').Default(path.Join(x.ConfigHome(), "config.ini")).ExistingFile()
).Short('c').Default(defaultConfigPath).ExistingFile()

add := app.Command("add", "Add a new feed.").Alias("a")
addURL := add.Arg("URL", "URL of the feed.").Required().String()

Loading…
Cancel
Save