code: def main(argv):
      
      usage = 'usage: %prog --help for options'
      opts = utils.parse(argv, RULES, ".splunkrc", usage=usage)
  
      context = binding.connect(**opts.kwargs)
      operation = None
  
      # splunk.binding.debug = True # for verbose information (helpful for debugging)
  
      # Extract from command line and build into variable args
      kwargs = {}
      for key in RULES.keys():
          if key in opts.kwargs:
              if key == "operation":
                  operation = opts.kwargs[key]
              else:
                  kwargs[key] = opts.kwargs[key]
  
      # no operation? if name present, default to list, otherwise list-all
      if not operation:
          if 'name' in kwargs:
              operation = 'list'
          else:
              operation = 'list-all'
      
      # pre-sanitize
      if (operation != "list" and operation != "create" 
                              and operation != "delete"
                              and operation != "list-all"):
          print("operation %s not one of list-all, list, create, delete" % operation)
          sys.exit(0)
  
      if 'name' not in kwargs and operation != "list-all":
          print("operation requires a name")
          sys.exit(0)
  
      # remove arg 'name' from passing through to operation builder, except on create
      if operation != "create" and operation != "list-all":
          name = kwargs['name']
          kwargs.pop('name')
  
      # perform operation on saved search created with args from cli
      if operation == "list-all":
          result = context.get("saved/searches",  **kwargs)
      elif operation == "list":
          result = context.get("saved/searches/%s" % name, **kwargs)
      elif operation == "create":
          result = context.post("saved/searches", **kwargs)
      else:
          result = context.delete("saved/searches/%s" % name, **kwargs)
      print("HTTP STATUS: %d" % result.status)
      xml_data = result.body.read().decode('utf-8')
      sys.stdout.write(xml_data)
docs: main entry