Split fetch from jobsearch into a separate fetcher command, and renamed fetch once to fts-once

job-search no longer has a fetch command. Its subcommands are now in
cmd/fetcher, which reads the same configuration: "fetcher service" runs
every enabled source's fetcher on its interval until stopped, and
"fetcher fts-once" (was "fetch once") fetches from Find a Tender once and
prints the releases as JSON. The new namea say what the commands do,
because service runs every source while fts-once fetches only from Find a
Tender.

The code stays in internal/cli/fetch, where NewCommands replaces the fetch
parent command. once.go is now fts_once.go and commandOnce is
commandFTSOnce. The README's usage, the config README and the find_a_tender
api_root comment now give the new command names.
This commit is contained in:
bwilliams committed 2026-10-16 09:13:10 +01:00
1 parent 5e61c11eb9
commit ac44b45f06
11 files changed
+155 -44

No files matched your search

+8 -19
View File
@@ -1,29 +1,18 @@
// Package fetch holds the fetcher commands: "fts-once" fetches from Find a
// Tender once and prints the releases, and "service" polls every enabled
// source on its interval.
package fetch
import (
"log/slog"
"github.com/spf13/cobra"
"git.avsdev.uk/Go/job-search/internal/cli"
)
// NewCommand returns the "fetch" command, which fetches opportunities once or
// as a service.
func NewCommand(opts *cli.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "fetch",
Short: "Fetch current opportunities",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent pre-run", "command", "fetch")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent post-run", "command", "fetch")
},
// NewCommands returns the fetcher commands, "fts-once" and "service".
func NewCommands(opts *cli.Options) []*cobra.Command {
return []*cobra.Command{
commandFTSOnce(opts),
commandService(opts),
}
cmd.AddCommand(commandOnce(opts))
cmd.AddCommand(commandService(opts))
return cmd
}
@@ -51,18 +51,20 @@ func filter(
return matching
}
func commandOnce(opts *cli.Options) *cobra.Command {
// commandFTSOnce returns the "fts-once" command, which fetches from Find a
// Tender once and prints the releases as JSON.
func commandFTSOnce(opts *cli.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "once",
Short: "Fetch current opportunities - single shot",
Use: "fts-once",
Short: "Fetch from Find a Tender once and print the releases as JSON",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent pre-run", "command", "fetch.once")
slog.Debug("command persistent pre-run", "command", "fts-once")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent post-run", "command", "fetch.once")
slog.Debug("command persistent post-run", "command", "fts-once")
},
RunE: func(cmd *cobra.Command, args []string) error {
slog.Debug("command run", "command", "fetch.once")
slog.Debug("command run", "command", "fts-once")
conf, err := opts.RunSetup(cmd, true, true)
if err != nil {
@@ -54,7 +54,7 @@ func TestFilter(t *testing.T) {
// Conflicting filters are rejected by cobra before anything is fetched.
func TestOnceFiltersExclusive(t *testing.T) {
cmd := commandOnce(&cli.Options{})
cmd := commandFTSOnce(&cli.Options{})
cmd.SetArgs([]string{"--planning", "--awards"})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
+4 -4
View File
@@ -18,15 +18,15 @@ import (
func commandService(opts *cli.Options) *cobra.Command {
cmd := &cobra.Command{
Use: "service",
Short: "Fetch current opportunities - background service",
Short: "Run every enabled source's fetcher on its interval until stopped",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent pre-run", "command", "fetch.service")
slog.Debug("command persistent pre-run", "command", "service")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
slog.Debug("command persistent post-run", "command", "fetch.service")
slog.Debug("command persistent post-run", "command", "service")
},
RunE: func(cmd *cobra.Command, args []string) error {
slog.Debug("command run", "command", "fetch.service")
slog.Debug("command run", "command", "service")
foreground, _ := cmd.Flags().GetBool("foreground")