code: def add_kind_filtering_cli(parser, *, default=None):
      parser.add_argument("--kinds", action="append")
  
      def process_args(args, *, argv=None):
          ns = vars(args)
  
          kinds = []
          for kind in ns.pop("kinds") or default or ():
              kinds.extend(kind.strip().replace(",", " ").split())
  
          if not kinds:
              match_kind = lambda k: True
          else:
              included = set()
              excluded = set()
              for kind in kinds:
                  if kind.startswith("-"):
                      kind = kind[1:]
                      excluded.add(kind)
                      if kind in included:
                          included.remove(kind)
                  else:
                      included.add(kind)
                      if kind in excluded:
                          excluded.remove(kind)
              if excluded:
                  if included:
                      ...  # XXX fail?
  
                  def match_kind(kind, *, _excluded=excluded):
                      return kind not in _excluded
  
              else:
  
                  def match_kind(kind, *, _included=included):
                      return kind in _included
  
          args.match_kind = match_kind
  
      return process_args
  
imports: import argparse
  import contextlib
  import logging
  import os
  import os.path
  import shutil
  import sys
  from .None import fsutil, strutil, iterutil, logging
label_desc: Use image node_id 18 for calling a global function with example usage: add_kind_filtering_cli(parser) and returns: process_args, unknown, unknown