1
0
Fork 0
mirror of https://github.com/vbatts/sl-feeds.git synced 2024-11-22 07:45:39 +00:00

main: add the --quiet flag

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-02-05 16:49:05 -05:00
parent fc518b86c5
commit dc39b5bdc7
Signed by: vbatts
GPG key ID: 10937E57733F1362

View file

@ -29,6 +29,10 @@ func main() {
Name: "dest, d", Name: "dest, d",
Usage: "Output RSS files to `DIR`", Usage: "Output RSS files to `DIR`",
}, },
cli.BoolFlag{
Name: "quiet, q",
Usage: "Less output",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "sample-config", Name: "sample-config",
Usage: "Output sample config file to stdout", Usage: "Output sample config file to stdout",
@ -39,7 +43,8 @@ func main() {
app.Action = func(c *cli.Context) error { app.Action = func(c *cli.Context) error {
if c.Bool("sample-config") { if c.Bool("sample-config") {
c := Config{ c := Config{
Dest: "$HOME/public_html/feeds/", Dest: "$HOME/public_html/feeds/",
Quiet: false,
Mirrors: []Mirror{ Mirrors: []Mirror{
Mirror{ Mirror{
URL: "http://slackware.osuosl.org/", URL: "http://slackware.osuosl.org/",
@ -76,7 +81,9 @@ func main() {
} }
dest := os.ExpandEnv(config.Dest) dest := os.ExpandEnv(config.Dest)
fmt.Printf("Writing to: %q\n", dest) if !c.Bool("quiet") {
fmt.Printf("Writing to: %q\n", dest)
}
/* /*
for each mirror in Mirrors for each mirror in Mirrors
if there is not a $release.RSS file, then fetch the whole ChangeLog if there is not a $release.RSS file, then fetch the whole ChangeLog
@ -90,7 +97,9 @@ func main() {
Release: release, Release: release,
} }
log.Printf("processing %q", repo.URL+"/"+repo.Release) if !c.Bool("quiet") {
log.Printf("processing %q", repo.URL+"/"+repo.Release)
}
stat, err := os.Stat(filepath.Join(dest, mirror.Prefix+release+".rss")) stat, err := os.Stat(filepath.Join(dest, mirror.Prefix+release+".rss"))
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
@ -111,7 +120,9 @@ func main() {
// compare times // compare times
entries, mtime, err = repo.NewerChangeLog(stat.ModTime()) entries, mtime, err = repo.NewerChangeLog(stat.ModTime())
if err != nil { if err != nil {
log.Println(release, err) if !(err == fetch.ErrNotNewer && c.Bool("quiet")) {
log.Println(release, err)
}
continue continue
} }
} }
@ -167,6 +178,7 @@ func main() {
// Config is read in to point to where RSS are written to, and the Mirrors to // Config is read in to point to where RSS are written to, and the Mirrors to
// be fetched from // be fetched from
type Config struct { type Config struct {
Quiet bool
Dest string Dest string
Mirrors []Mirror Mirrors []Mirror
} }