Ejemplo n.º 1
0
def main(argv):
  defaults = {
    'name': DEFAULT_NAME,
    'description': DEFAULT_DESCRIPTION,
    'labels': DEFAULT_LABELS
  }
  piv = Pivotal(MY_TOKEN, PROJECT_ID, defaults)

  if len(argv) == 0:
    usage()
    sys.exit(2)

  command = argv[0]

  if command not in ('create', 'search'):
    usage()
    sys.exit(2)

  new_args = argv[1:]

  if command == 'create':
    try:
      opts, args = getopt.getopt(new_args, "t:n:l:", ["type=", "name=", "labels="])
    except getopt.GetoptError:
      usage()
      sys.exit(2)

    name = ''
    story_type = "feature"
    extra_labels = []

    for opt, arg in opts:
      if opt in ("-n", "--name"):
        name = arg
      elif opt in ("-t", "--type"):
        if arg in ("f", "feature"):
          story_type = "feature"
        elif arg in ("b", "bug"):
          story_type = "bug"
        elif arg in ("c", "chore"):
          story_type = "chore"
      elif opt in ("-l", "--labels"):
        extra_labels = re.findall(r'\w+', arg)

    if name == '':
      usage()
      sys.exit(2)

    story = piv.create(name, story_type, extra_labels)
    print storySummary(story)

  elif command == 'list':
    pass
    
  elif command == 'update':
    try:
      opts, args = getopt.getopt(new_args, "c:", ["comment="])
    except getopt.GetoptError:
      usage()
      sys.exit(2)

    for o, a in opts:
      if o in ("-c", "--comment"):
        pass

  elif command == 'search':
    try:
      opts, args = getopt.getopt(new_args, "l:", ["limit="])
    except getopt.GetoptError:
      usage()
      sys.exit(2)

    limit = 99
    for opt, arg in opts:
      if opt in ("-l", "--limit"):
        limit = int(arg)

    search = " ".join(args)
    matches = piv.search(search)
    for match in matches[:limit]:
      print storySummary(match)