Class: Toolshed::Commands::CreateBranch
- Inherits:
-
Object
- Object
- Toolshed::Commands::CreateBranch
- Defined in:
- lib/toolshed/commands/create_branch.rb
Overview
Create a branch from a given set of parameters
Class Method Summary collapse
-
.cli_options ⇒ Object
rubocop:disable Metrics/MethodLength.
Instance Method Summary collapse
-
#execute(_args, options = {}) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #read_user_input_branch_from(message, options) ⇒ Object
- #read_user_input_branch_name(message, options) ⇒ Object
Class Method Details
.cli_options ⇒ Object
rubocop:disable Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/toolshed/commands/create_branch.rb', line 7 def self. # rubocop:disable Metrics/MethodLength { banner: 'Usage: create_branch [options]', options: { branch_name: { short_on: '-b' }, branch_from: { short_on: '-f' } } } end |
Instance Method Details
#execute(_args, options = {}) ⇒ Object
rubocop:disable Metrics/MethodLength
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/toolshed/commands/create_branch.rb', line 21 def execute(_args, = {}) # rubocop:disable Metrics/MethodLength branch_name = read_user_input_branch_name('Branch name:', ) branch_from = read_user_input_branch_from('Branch from:', ) branch = Toolshed::Git::Branch.new(from_remote_branch_name: branch_from, to_remote_branch_name: branch_name) # rubocop:disable Metrics/LineLength branch.create Toolshed.die rescue Veto::InvalidEntity => e Toolshed.logger.fatal 'Unable to create branch due to the following errors' # rubocop:disable Metrics/LineLength e..each do |key, value| Toolshed.logger.fatal "#{key}: #{value}" end Toolshed.die end |
#read_user_input_branch_from(message, options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/toolshed/commands/create_branch.rb', line 51 def read_user_input_branch_from(, ) return [:branch_from] if .key?(:branch_from) # if branch-name was supplied then default to master if not supplied return Toolshed::Git::DEFAULT_BRANCH_FROM if .key?(:branch_name) puts value = $stdin.gets.chomp while value.empty? puts 'Branch from cannot be empty' puts value = $stdin.gets.chomp end value end |
#read_user_input_branch_name(message, options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/toolshed/commands/create_branch.rb', line 36 def read_user_input_branch_name(, ) return [:branch_name] if .key?(:branch_name) puts value = $stdin.gets.chomp while value.empty? puts 'Branch name cannot be empty' puts value = $stdin.gets.chomp end value end |