Class: Git::Whistles::Youtrack::Branch

Inherits:
App
  • Object
show all
Defined in:
lib/git-whistles/youtrack/branch.rb

Instance Method Summary collapse

Methods inherited from App

run!

Constructor Details

#initialize(current_dir: ENV['PWD']) ⇒ Branch

Returns a new instance of Branch.



10
11
12
13
# File 'lib/git-whistles/youtrack/branch.rb', line 10

def initialize(current_dir: ENV['PWD'])
  @current_dir = current_dir
  super()
end

Instance Method Details

#main(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git-whistles/youtrack/branch.rb', line 15

def main(args)
  super

  parse_args!(args)
  if args.count < 1
    puts Term::ANSIColor.yellow usage
    return false
  end

  ticket = get_ticket_from args[0]
  if ticket.nil?
    die "Could not find ticket #{args[0]}"
    return false
  end

  suggested_branch_name = suggested_branch_name_from(ticket)
  print_suggested_branch suggested_branch_name

  user_branch_name = read_user_answer
  show_and_exit "Cancelled by user" if user_branch_name.nil?

  final_branch_name = user_branch_name.empty? ? suggested_branch_name : user_branch_name
  create_branch final_branch_name

  puts Term::ANSIColor.green 'Created branch'
  true
end