Class: Toolshed::Commands::DeleteBranch
- Inherits:
-
Object
- Object
- Toolshed::Commands::DeleteBranch
- Defined in:
- lib/toolshed/commands/delete_branch.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
Class Method Summary collapse
Instance Method Summary collapse
- #confirm_delete ⇒ Object
- #execute(args, options = {}) ⇒ Object
- #read_user_input(message, options) ⇒ Object
Instance Attribute Details
#branch ⇒ Object
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_options ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/toolshed/commands/delete_branch.rb', line 10 def self. { banner: 'Usage: delete_branch [options]', options: { branch_name: { short_on: '-b', } } } end |
Instance Method Details
#confirm_delete ⇒ Object
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, = {}) branch_name = read_user_input("Ticket ID or branch name:", ) 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(, ) return [:branch_name] if (.has_key?(:branch_name)) puts value = $stdin.gets.chomp until (!value.empty?) puts "Branch name cannot be empty" puts value = $stdin.gets.chomp end value end |