diff --git a/cmd/aem/root.go b/cmd/aem/root.go index ca77954..1a29a7a 100644 --- a/cmd/aem/root.go +++ b/cmd/aem/root.go @@ -71,16 +71,27 @@ func (c *CLI) rootFlags(cmd *cobra.Command) { cmd.PersistentFlags().StringSliceP("instance-url", "U", cv.GetStringSlice("instance.adhoc_url"), "Use only AEM instance(s) at ad-hoc specified URL(s)") _ = cv.BindPFlag("instance.adhoc_url", cmd.PersistentFlags().Lookup("instance-url")) - cmd.PersistentFlags().StringP("instance-id", "I", cv.GetString("instance.filter.id"), "Use only AEM instance configured with the exact ID") + cmd.PersistentFlags().StringSliceP("instance-id", "I", cv.GetStringSlice("instance.filter.id"), "Use only AEM instance(s) configured with the exact ID") _ = cv.BindPFlag("instance.filter.id", cmd.PersistentFlags().Lookup("instance-id")) - cmd.PersistentFlags().BoolP("instance-author", "A", cv.GetBool("instance.filter.authors"), "Use only AEM author instance") + cmd.PersistentFlags().BoolP("instance-author", "A", cv.GetBool("instance.filter.authors"), "Use only AEM author instance(s)") _ = cv.BindPFlag("instance.filter.authors", cmd.PersistentFlags().Lookup("instance-author")) - cmd.PersistentFlags().BoolP("instance-publish", "P", cv.GetBool("instance.filter.publishes"), "Use only AEM publish instance") + cmd.PersistentFlags().BoolP("instance-publish", "P", cv.GetBool("instance.filter.publishes"), "Use only AEM publish instance(s)") _ = cv.BindPFlag("instance.filter.publishes", cmd.PersistentFlags().Lookup("instance-publish")) - cmd.MarkFlagsMutuallyExclusive("instance-author", "instance-publish") + cmd.PersistentFlags().BoolP("instance-local", "L", cv.GetBool("instance.filter.locals"), "Use only AEM local instance(s)") + _ = cv.BindPFlag("instance.filter.locals", cmd.PersistentFlags().Lookup("instance-local")) + + cmd.PersistentFlags().BoolP("instance-remote", "R", cv.GetBool("instance.filter.remotes"), "Use only AEM remote instance(s)") + _ = cv.BindPFlag("instance.filter.remotes", cmd.PersistentFlags().Lookup("instance-remote")) + + cmd.PersistentFlags().StringP("instance-classifier-prefix", "C", cv.GetString("instance.filter.classifier-prefix"), "Use only AEM instance(s) with proper classifier prefix") + _ = cv.BindPFlag("instance.filter.classifier-prefix", cmd.PersistentFlags().Lookup("instance-classifier-prefix")) + + cmd.MarkFlagsMutuallyExclusive("instance-url", "instance-id", "instance-author", "instance-publish") + cmd.MarkFlagsMutuallyExclusive("instance-url", "instance-id", "instance-local", "instance-remote") + cmd.MarkFlagsMutuallyExclusive("instance-url", "instance-id", "instance-classifier-prefix") cmd.PersistentFlags().String("instance-processing", cv.GetString("instance.processing_mode"), "Controls processing mode for instances ("+(strings.Join(instance.ProcessingModes(), "|")+")")) _ = cv.BindPFlag("instance.processing_mode", cmd.PersistentFlags().Lookup("instance-processing")) diff --git a/pkg/instance_manager.go b/pkg/instance_manager.go index 893ee77..02a54f9 100644 --- a/pkg/instance_manager.go +++ b/pkg/instance_manager.go @@ -21,10 +21,13 @@ type InstanceManager struct { AdHocURLs []string - FilterID string - FilterAuthors bool - FilterPublishes bool - ProcessingMode string + FilterIDs []string + FilterAuthors bool + FilterPublishes bool + FilterLocals bool + FilterRemotes bool + FilterClassifierPrefix string + ProcessingMode string } func NewInstanceManager(aem *AEM) *InstanceManager { @@ -35,9 +38,20 @@ func NewInstanceManager(aem *AEM) *InstanceManager { result.AdHocURLs = cv.GetStringSlice("instance.adhoc_url") - result.FilterID = cv.GetString("instance.filter.id") + result.FilterIDs = cv.GetStringSlice("instance.filter.id") result.FilterAuthors = cv.GetBool("instance.filter.authors") result.FilterPublishes = cv.GetBool("instance.filter.publishes") + if !result.FilterAuthors && !result.FilterPublishes { + result.FilterAuthors = true + result.FilterPublishes = true + } + result.FilterLocals = cv.GetBool("instance.filter.locals") + result.FilterRemotes = cv.GetBool("instance.filter.remotes") + if !result.FilterLocals && !result.FilterRemotes { + result.FilterLocals = true + result.FilterRemotes = true + } + result.FilterClassifierPrefix = cv.GetString("instance.filter.classifier-prefix") result.ProcessingMode = cv.GetString("instance.processing_mode") result.LocalOpts = NewLocalOpts(result) @@ -165,33 +179,26 @@ func (im *InstanceManager) newFromConfig(id string) *Instance { func (im *InstanceManager) filter(instances []Instance) []Instance { result := []Instance{} - if im.FilterID != "" { + if len(im.FilterIDs) > 0 { for _, i := range instances { - if i.id == im.FilterID { - result = append(result, i) - break + for _, filterID := range im.FilterIDs { + if i.id == filterID { + result = append(result, i) + break + } } } } else { - if im.FilterAuthors == im.FilterPublishes { - result = instances - } else { - if im.FilterAuthors { - for _, i := range instances { - if i.IsAuthor() { - result = append(result, i) - } - } - } - if im.FilterPublishes { - for _, i := range instances { - if i.IsPublish() { - result = append(result, i) - } - } + for _, i := range instances { + filterLocation := im.FilterAuthors && i.IsAuthor() || im.FilterPublishes && i.IsPublish() + filterRole := im.FilterLocals && i.IsLocal() || im.FilterRemotes && i.IsRemote() + filterClassifier := strings.HasPrefix(i.IDInfo().Classifier, im.FilterClassifierPrefix) + if filterLocation && filterRole && filterClassifier { + result = append(result, i) } } } + sort.SliceStable(result, func(i, j int) bool { return strings.Compare(result[i].id, result[j].id) < 0 })