package skiprules import ( "fmt" "log/slog" "github.com/spf13/cobra" "git.avsdev.uk/Go/job-search/internal/cli" ) // commandCheck returns the "check" command, which reports whether a rules // file is valid. func commandCheck(opts *cli.Options) *cobra.Command { return &cobra.Command{ Use: "check [file]", Short: "Check a skip rules file (default: sources.skip_rules_file)", Args: cobra.MaximumNArgs(1), PersistentPreRun: func(cmd *cobra.Command, args []string) { slog.Debug("command persistent pre-run", "command", "skip-rules.check") }, PersistentPostRun: func(cmd *cobra.Command, args []string) { slog.Debug("command persistent post-run", "command", "skip-rules.check") }, RunE: func(cmd *cobra.Command, args []string) error { slog.Debug("command run", "command", "skip-rules.check") conf, err := opts.RunSetup(cmd, true, true) if err != nil { return fmt.Errorf("load configuration: %w", err) } rules, path, err := loadRules(conf, args) if err != nil { return err } _, err = fmt.Fprintf( cmd.OutOrStdout(), "%s is valid: %s\n", path, describeRules(rules), ) return err }, } }