cli.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import json
  2. import click
  3. from terminaltables import AsciiTable
  4. from trello import Trello
  5. @click.group()
  6. def cli():
  7. pass
  8. @click.command()
  9. def boards():
  10. t = Trello()
  11. boards = t.boards()
  12. table_data = [
  13. ['Name', 'URL', 'ID']
  14. ]
  15. for board in boards:
  16. table_data.append([board['name'], board['url'], board['id']])
  17. table = AsciiTable(table_data)
  18. print(table.table)
  19. @click.command()
  20. @click.option('-i', '--id', required=False, type=click.STRING)
  21. @click.option('-n', '--name', required=False, type=click.STRING)
  22. def cards(id, name):
  23. if id is None and name is None:
  24. raise click.UsageError(
  25. "Either the board ID (-i) or name (-n) is required. ")
  26. t = Trello()
  27. if name is not None:
  28. id = t.lookupBoard(name)
  29. cards = t.cards(id)
  30. for listy in cards:
  31. print("\t", listy)
  32. for c in cards[listy]:
  33. print(" *", c)
  34. print()
  35. @click.command()
  36. @click.option('-q', '--query', required=True, type=click.STRING)
  37. # TODO: type filtering
  38. @click.option('-t', '--type', required=False, type=click.STRING)
  39. def search(query, type):
  40. t = Trello()
  41. # TODO: need to build classes for actions, ards, boards, organizations,
  42. # members
  43. resp = t.search(query)
  44. print(json.dumps(resp, sort_keys=True, indent=4))
  45. if __name__ == '__main__':
  46. cli.add_command(boards)
  47. cli.add_command(cards)
  48. cli.add_command(search)
  49. cli()