mirror of
https://github.com/pikami/rss-dl.git
synced 2024-11-27 16:08:13 +00:00
Added configuration flags
This commit is contained in:
parent
39d14eaf7a
commit
e13f98eb4a
@ -29,7 +29,7 @@ func WriteToFile(filename string, content string) {
|
||||
// InitOutputDirectory - Creates output directory
|
||||
func InitOutputDirectory(path string) {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
os.Mkdir(path, os.ModePerm)
|
||||
os.MkdirAll(path, os.ModePerm)
|
||||
}
|
||||
}
|
||||
|
||||
|
13
main.go
13
main.go
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
. "./fileio"
|
||||
@ -13,17 +12,13 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
if len(args) < 1 {
|
||||
fmt.Println("Usage: rss-dl [FEED_URL]")
|
||||
return
|
||||
}
|
||||
GetConfig()
|
||||
|
||||
fp := gofeed.NewParser()
|
||||
LogInfo("Downloading " + args[0])
|
||||
feed, _ := fp.ParseURL(args[0])
|
||||
LogInfo("Downloading " + Config.FeedURL)
|
||||
feed, _ := fp.ParseURL(Config.FeedURL)
|
||||
|
||||
outputDir := ToCleanString(feed.Title)
|
||||
outputDir := Config.OutputPath + "/" + ToCleanString(feed.Title)
|
||||
InitOutputDirectory(outputDir)
|
||||
|
||||
feedInfoPath := outputDir + "/feed_details.json"
|
||||
|
29
structs/config.go
Normal file
29
structs/config.go
Normal file
@ -0,0 +1,29 @@
|
||||
package structs
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config - Runtime configuration
|
||||
var Config struct {
|
||||
FeedURL string
|
||||
OutputPath string
|
||||
}
|
||||
|
||||
// GetConfig - Returns Config object
|
||||
func GetConfig() {
|
||||
outputPath := flag.String("output", ".", "Output path")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) < 1 {
|
||||
fmt.Println("Usage: rss-dl [OPTIONS] FEED_URL")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
Config.FeedURL = flag.Args()[len(args)-1]
|
||||
Config.OutputPath = *outputPath
|
||||
}
|
Loading…
Reference in New Issue
Block a user