From d342b6f542ebe4f8766315f262cf764f6ac52de4 Mon Sep 17 00:00:00 2001 From: nytpu Date: Sat, 20 Mar 2021 09:55:51 -0600 Subject: [PATCH] add regenerate command --- comitium.go | 12 ++++++++++++ doc/comitium.1.scd | 7 +++++++ flags.go | 9 ++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/comitium.go b/comitium.go index 418e220..7a02521 100644 --- a/comitium.go +++ b/comitium.go @@ -67,6 +67,18 @@ func main() { fmt.Fprintf(os.Stderr, "Error writing feed: %v\n", err) os.Exit(1) } + case "regenerate": + argCheck(c.Args(), 0, false, "'regenerate' doesn't take an argument!") + err = core.Data.WriteSubs(dataPath) + if err != nil { + fmt.Fprintf(os.Stderr, "Error writing subscriptions: %v\n", err) + os.Exit(1) + } + err = core.Data.WriteFeed(dataPath) + if err != nil { + fmt.Fprintf(os.Stderr, "Error writing feed: %v\n", err) + os.Exit(1) + } case "add": argCheck(c.Args(), 1, true, "Please provide a URL to add.") diff --git a/doc/comitium.1.scd b/doc/comitium.1.scd index 825e29a..fe70106 100644 --- a/doc/comitium.1.scd +++ b/doc/comitium.1.scd @@ -23,6 +23,10 @@ variety of feed formats: *refresh* [_FLAGS_] Check for new updates to subscriptions and update aggregator page. +*regenerate* + Will regenerate all the files created by comitium using cached entries + without fetching any feeds. + *add* [_FLAGS_] <_LINK_> [_TITLE_] Add a new subscription. _LINK_ is a link to the feed or watched URL. _TITLE_ is an optional title for the feed, otherwise a title will be @@ -30,6 +34,9 @@ variety of feed formats: first heading on a page is used as a title. For ATOM, RSS, and JSON feeds, the provided title is used. For a page being watched for changes, the URL itself is used. + Also to note: when adding a new subscription, you *do not* need to run + *refresh* afterwards, *add* will automatically fetch the entries and + regenerate the .gmi and .json files. *remove* <_LINK_> Remove a subscription at _LINK_. diff --git a/flags.go b/flags.go index 88d755a..e9bd942 100644 --- a/flags.go +++ b/flags.go @@ -22,6 +22,7 @@ type command struct { // info about all the accepted commands var commandInfo = []command{ {"refresh", "Check for new updates to subscriptions"}, + {"regenerate", "Regenerate all files generated by comitium without checking for new updates."}, {"add", "Add a new subscription"}, {"remove", "Remove a subscription"}, {"help", "Print usage information"}, @@ -29,9 +30,10 @@ var commandInfo = []command{ } var commands = map[string]*flag.FlagSet{ - "refresh": flag.NewFlagSet("refresh", flag.ExitOnError), - "add": flag.NewFlagSet("add", flag.ExitOnError), - "remove": flag.NewFlagSet("remove", flag.ExitOnError), + "refresh": flag.NewFlagSet("refresh", flag.ExitOnError), + "regenerate": flag.NewFlagSet("regenerate", flag.ExitOnError), + "add": flag.NewFlagSet("add", flag.ExitOnError), + "remove": flag.NewFlagSet("remove", flag.ExitOnError), } // set up various flags for each individual command @@ -43,6 +45,7 @@ var ( `Watch a page instead of adding it as a feed.`, ) + // refresh refreshWorkersFlag = commands["refresh"].IntP( "num-workers", "n", 5, // 5 workers is a safe default