Class: Toolshed::Commands::DeleteBranch

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



8
9
10
# File 'lib/toolshed/commands/delete_branch.rb', line 8

def branch
  @branch
end

Class Method Details

.cli_optionsObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/toolshed/commands/delete_branch.rb', line 10

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

Instance Method Details

#confirm_deleteObject



47
48
49
50
51
52
53
54
55
# File 'lib/toolshed/commands/delete_branch.rb', line 47

def confirm_delete
  choices = "yn"
  answer = ask("Are you sure you want to delete #{branch.name} [#{choices}]? ") do |q|
    q.echo      = false
    q.character = true
    q.validate  = /\A[#{choices}]\Z/
  end
  answer == 'y'
end

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



21
22
23
24
25
26
27
28
29
30
# File 'lib/toolshed/commands/delete_branch.rb', line 21

def execute(args, options = {})
  branch_name = read_user_input("Ticket ID or branch name:", options)
  self.branch = Toolshed::Git::Branch.new(branch_name: branch_name)
  if confirm_delete
    branch.delete(branch_name)
  else
    Toolshed.logger.info "Branch '#{branch.name}' was not deleted."
  end
  Toolshed.die
end

#read_user_input(message, options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/toolshed/commands/delete_branch.rb', line 32

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