lib/trello_flow/main.rb in trello_flow-1.0.1 vs lib/trello_flow/main.rb in trello_flow-1.1.0

- old
+ new

@@ -2,18 +2,22 @@ class Main def initialize(config = Config.new) @config = config end - def start(input) - if input.to_s.start_with?("http") - start_with_url(input) - elsif input.present? - start_new_item(input) + def start(name) + if name.to_s.start_with?("http") + card = Api::Card.find_by_url(name) + name = nil else - start_blank + card = find_or_create_card(name) end + + checklist = card.find_or_create_checklist + item = checklist.select_or_create_item(name) + item.assign(username) + Branch.from_item(item).checkout end def open Branch.current.open_trello(username) end @@ -29,31 +33,25 @@ Cleanup.new(Branch.current.target).run end private - def start_with_url(url) - card = Api::Card.find_by_url(url) - checklist = card.find_or_create_checklist - item = checklist.select_or_create_item - item.assign(username) - Branch.from_item(item).checkout + def find_or_create_card(name) + if Cli.ask("(n)ew or (e)xisting card?") == "n" + create_new_card(name) + else + pick_existing_card + end end - def start_blank - card = Table.new(Api::Card.for(username)).pick - checklist = card.find_or_create_checklist - item = checklist.select_or_create_item - item.assign(username) - Branch.from_item(item).checkout + def create_new_card(name) + board = Table.pick(Api::Member.current.boards.active) + list = Table.pick(board.lists) + list.cards.create name: Cli.ask("Input card title [#{name}]:").presence || name end - def start_new_item(name) - card = Table.new(Api::Card.for(username)).pick - checklist = card.find_or_create_checklist - item = checklist.add_item(name) - item.assign(username) - Branch.from_item(item).checkout + def pick_existing_card + Table.pick Api::Card.for(username) end def username @_username ||= Api::Member.current.username end