Files
bwilliams 0543762330 Added skip rules, which mark new opportunities Skipped when they're fetched
sources.skip_rules_file names a JSON file of filters, each with a
comment, an active flag, a logic mode ("or" by default, or "and") and
rules by buyer, title words or CPV codes. The fetcher applies them
before saving, so only new opportunities are marked; the marks of
stored ones are never touched. CPV rules match when the opportunity's
codes are all in the list, or any of them with exclusive false, and
by prefix with exact false.

The file is read again when its time or size changes: an invalid edit
is logged and the last good rules kept, and a deleted file means no
rules until it's back. fetcher service and serve refuse to start if it
is define but missing or invalid.

job-search skip-rules check validates a rules file, and skip-rules
apply marks the stored opportunities that match Skipped, or only lists
them with --dry-run.
2026-10-20 08:55:19 +01:00

91 lines
2.5 KiB
Go

/*
Copyright © 2026 Craig Williams <craig@avsdev.uk>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Command job-search. Run `job-search --help` for usage.
package main
import (
"fmt"
"log/slog"
"os"
"strings"
"github.com/spf13/cobra"
"git.avsdev.uk/Go/job-search/internal/cli"
"git.avsdev.uk/Go/job-search/internal/cli/config"
"git.avsdev.uk/Go/job-search/internal/cli/migrate"
"git.avsdev.uk/Go/job-search/internal/cli/serve"
"git.avsdev.uk/Go/job-search/internal/cli/skiprules"
"git.avsdev.uk/Go/job-search/internal/cli/version"
)
// newRootCmd builds the command tree. It returns a fresh tree on each call so
// tests can run commands in isolation.
func newRootCmd() *cobra.Command {
opts := &cli.Options{}
root := &cobra.Command{
Use: "job-search",
Short: "JobSearch - AVSDev Future Opportunities!",
Long: `JobSearch is a scraping tool for searching for possible contract
opportunities.
`,
SilenceUsage: true, // don't print usage on runtime errors
SilenceErrors: true, // main prints the error once
CompletionOptions: cobra.CompletionOptions{
HiddenDefaultCmd: true,
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
cli.SetupInitialLogging(cmd)
slog.Debug("command persistent pre-run", "command", "root")
slog.Debug(
"command",
"path", strings.Join(strings.Split(cmd.CommandPath(), " ")[1:], " "),
)
return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
slog.Debug("command persistent post-run", "command", "root")
return opts.Finish()
},
}
cobra.EnableTraverseRunHooks = true
opts.Bind(root)
root.AddCommand(
version.NewCommand(),
config.NewCommand(opts),
migrate.NewCommand(opts),
serve.NewCommand(opts),
skiprules.NewCommand(opts),
)
return root
}
func main() {
if err := newRootCmd().Execute(); err != nil {
fmt.Fprintln(os.Stderr, "job-search:", err)
os.Exit(1)
}
}