From 4e7ea234d68adadb2f8aad492205e90e5a6bd6fd Mon Sep 17 00:00:00 2001 From: Dave Gaeddert Date: Tue, 6 Jul 2021 11:19:02 -0500 Subject: [PATCH] Add ci dependency path filter and negation to paths and types options --- cmd/deps/ci.go | 6 ++++-- internal/runner/ci.go | 4 ++-- internal/runner/local.go | 2 +- internal/runner/main.go | 26 +++++++++++++++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/cmd/deps/ci.go b/cmd/deps/ci.go index 5eb12d7..7ce562d 100644 --- a/cmd/deps/ci.go +++ b/cmd/deps/ci.go @@ -8,6 +8,7 @@ import ( var ciManual bool var ciTypes []string +var ciPaths []string var ciQuiet bool var ciCMD = &cobra.Command{ @@ -20,7 +21,7 @@ var ciCMD = &cobra.Command{ } auto := !ciManual - if err := runner.CI(auto, ciTypes); err != nil { + if err := runner.CI(auto, ciTypes, ciPaths); err != nil { printErrAndExitFailure(err) } }, @@ -29,6 +30,7 @@ var ciCMD = &cobra.Command{ func init() { ciCMD.Flags().BoolVarP(&ciManual, "manual", "m", false, "do not automatically configure repo") ciCMD.Flags().BoolVarP(&ciQuiet, "quiet", "q", false, "disable verbose output") - ciCMD.Flags().StringArrayVarP(&ciTypes, "type", "t", []string{}, "only run on specified dependency types") + ciCMD.Flags().StringArrayVarP(&ciTypes, "type", "t", []string{}, "only run on specified dependency types (use ! to negate)") + ciCMD.Flags().StringArrayVarP(&ciPaths, "path", "p", []string{}, "only run on specified dependency paths (use ! to negate)") rootCmd.AddCommand(ciCMD) } diff --git a/internal/runner/ci.go b/internal/runner/ci.go index 723d3e5..22d502c 100644 --- a/internal/runner/ci.go +++ b/internal/runner/ci.go @@ -24,7 +24,7 @@ type updateResult struct { err error } -func CI(autoconfigure bool, types []string) error { +func CI(autoconfigure bool, types []string, paths []string) error { api, err := billing.NewAPI() if err != nil { @@ -79,7 +79,7 @@ func CI(autoconfigure bool, types []string) error { return err } - allUpdates, err := collectUpdates(cfg, types) + allUpdates, err := collectUpdates(cfg, types, paths) if err != nil { return err } diff --git a/internal/runner/local.go b/internal/runner/local.go index cfc8b5d..19f1265 100644 --- a/internal/runner/local.go +++ b/internal/runner/local.go @@ -27,7 +27,7 @@ func Local() error { return err } - allUpdates, err := collectUpdates(cfg, []string{}) + allUpdates, err := collectUpdates(cfg, []string{}, []string{}) if err != nil { return err } diff --git a/internal/runner/main.go b/internal/runner/main.go index 7f50152..574b3cc 100644 --- a/internal/runner/main.go +++ b/internal/runner/main.go @@ -46,20 +46,40 @@ func organizeUpdates(updates Updates) (Updates, Updates, Updates, error) { return newUpdates, outdatedUpdates, existingUpdates, nil } -func collectUpdates(cfg *config.Config, types []string) (Updates, error) { +func collectUpdates(cfg *config.Config, types []string, paths []string) (Updates, error) { if len(types) > 0 { output.Event("Only collecting types: %s", strings.Join(types, ", ")) } typesMap := map[string]bool{} for _, t := range types { - typesMap[t] = true + if strings.HasPrefix(t, "!") { + typesMap[t[1:]] = false + } else { + typesMap[t] = true + } + } + + if len(paths) > 0 { + output.Event("Only collecting paths: %s", strings.Join(paths, ", ")) + } + pathsMap := map[string]bool{} + for _, p := range paths { + if strings.HasPrefix(p, "!") { + pathsMap[p[1:]] = false + } else { + pathsMap[p] = true + } } updates := Updates{} for index, dependencyConfig := range cfg.Dependencies { - if _, ok := typesMap[dependencyConfig.Type]; len(typesMap) > 0 && !ok { + if enabled, ok := typesMap[dependencyConfig.Type]; len(typesMap) > 0 && (!ok || !enabled) { + continue + } + + if enabled, ok := pathsMap[dependencyConfig.Path]; len(pathsMap) > 0 && (!ok || !enabled) { continue }