ASSETS.cli.config do |cnf| cnf.input_filters do |filters| filters.add("-input-filter-tags-all", "only those that have ALL the specified tags separated by '|'") do |input, session, options| tags = SCR.get_arg("-input-filter-tags-all", with_param: true).upcase.split("|") options.deep_merge!(input: {filter: {filter_tags: {all: tags}}}) input.filter_tags_all(tags).tap do |filtered| msg = "Filtered #{filtered.count} entries (out of #{input.count}) with 'all' filter_tags #{tags}" session.logger.info(msg) end end filters.add("-input-filter-tags-any", "only those that have ANY the specified tags separated by '|'") do |input, session, options| tags = SCR.get_arg("-input-filter-tags-any", with_param: true).upcase.split("|") options.deep_merge!(input: {filter: {filter_tags: {any: tags}}}) input.filter_tags_any(tags).tap do |filtered| msg = "Filtered #{filtered.count} entries (out of #{input.count}) with 'any' filter_tags #{tags}" session.logger.info(msg) end end filters.add("-input-filter-tags-tree", "only those that have ANY tag in the specified subtrees separated by '|'") do |input, session, options| top_tags = SCR.get_arg("-input-filter-tags-tree", with_param: true).upcase.split("|") tags = top_tags.each_with_object([]) do |top, tags| tags.concat(session.tagtree.node(top).tags) end.uniq options.deep_merge!(input: {filter: {filter_tags: {tree: top_tags, any: tags}}}) input.filter_tags_any(tags).tap do |filtered| msg = "Filtered #{filtered.count} entries (out of #{input.count}) with 'any' filter_tags in subtrees #{top_tags}" session.logger.info(msg) end end filters.add("-input-no-id", "only those that do not have 'id' or 'external_id' specified") do |input, session, options| options.deep_merge!(input: {filter: {external_id: nil}}) input.select do |entry| !!(entry.id || entry.external_id) end.yield_self do |filtered| input.newFrom filtered end end #filters.add("-input-supervisors") do |people, session, options| # options.deep_merge!(input: {filter: {subordinates: true}}) # people.newFrom people.to_a.select {|person| person.subordinates > 0} #end filters.add("-input-supervisor-id", "only those with certain supervisor id or external_id") do |input, session, options| id = SCR.get_arg("-input-supervisor-id", with_param: true) options.deep_merge!(input: {filter: {supervisor_id: id}}) #unless sup = entries.find({"id" => id, "external_id" => id}) # raise "Could not find anyone in the input with that id '#{id}'" #end input.supervisor_id(id) end end end