Class: Toolshed::Commands::CheckoutBranch

Inherits:
Object
  • Object
show all
Defined in:
lib/toolshed/commands/checkout_branch.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cli_optionsObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/toolshed/commands/checkout_branch.rb', line 6

def self.cli_options
  {
    banner: 'Usage: checkout_branch [options]',
    options: {
      branch_name: {
        short_on: '-b',
      }
    }
  }
end

Instance Method Details

#execute(args, options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/toolshed/commands/checkout_branch.rb', line 17

def execute(args, options = {})
  branch_name = read_user_input("Ticket ID or Branch Name:", options)
  Toolshed::Git::Branch.checkout(branch_name)
  Toolshed.die
end

#read_user_input(message, options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/toolshed/commands/checkout_branch.rb', line 23

def read_user_input(message, options)
  return options[:branch_name] if (options.has_key?(:branch_name))

  puts message
  value = $stdin.gets.chomp

  until (!value.empty?)
    puts "Branch name cannot be empty"
    puts message
    value = $stdin.gets.chomp
  end

  value
end