Module: PromptHandler

Included in:
Commit
Defined in:
lib/get/subcommand/commit/prompt.rb

Overview

Module for asking to the user informations about a commit message.

Constant Summary collapse

STRING_VALUE_VALIDATOR =
/\s*\S+\s*/
BODY_END_DELIMITER =
"\n\n\n"
DEFAULT_TYPES =
%i[
  feat
  fix
  build
  chore
  ci
  docs
  style
  refactor
  perf
  test
].freeze
@@cli =
HighLine.new
@@custom_values_initialized =
nil
@@custom_types =
[]
@@custom_scopes =
[]

Instance Method Summary collapse

Instance Method Details

#ask_for_breakingObject



82
83
84
85
86
# File 'lib/get/subcommand/commit/prompt.rb', line 82

def ask_for_breaking
  @@cli.agree('Does the commit contain a breaking change? (yes/no) ') do |question|
    question.default = false
  end
end

#ask_for_messageObject



95
96
97
98
99
# File 'lib/get/subcommand/commit/prompt.rb', line 95

def ask_for_message
  # This method needs a special implementation as the body message can span multiple lines.
  @@cli.puts('The body of the commit (ends after 3 new lines):')
  @@cli.input.gets(BODY_END_DELIMITER)
end

#ask_for_scopeObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/get/subcommand/commit/prompt.rb', line 64

def ask_for_scope
  extract_types_and_scopes
  @@cli.choose do |menu|
    menu.flow = :columns_down
    menu.prompt = 'Choose the scope of your commit: '
    @@custom_scopes.each do |scope|
      menu.choice(scope.to_sym)
    end
    menu.choice('Create a new scope') do |_|
      @@cli.ask('Write the new scope to use', String) do |question|
        question.verify_match = true
        question.validate = STRING_VALUE_VALIDATOR
      end
    end
    menu.choice('None') { '' }
  end
end

#ask_for_summaryObject



88
89
90
91
92
93
# File 'lib/get/subcommand/commit/prompt.rb', line 88

def ask_for_summary
  @@cli.ask('The summary of the commit:') do |question|
    question.verify_match = true
    question.validate = STRING_VALUE_VALIDATOR
  end
end

#ask_for_typeObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/get/subcommand/commit/prompt.rb', line 47

def ask_for_type
  extract_types_and_scopes
  @@cli.choose do |menu|
    menu.flow = :columns_down
    menu.prompt = 'Choose the type of your commit: '
    DEFAULT_TYPES.union(@@custom_types).each do |type|
      menu.choice(type.to_sym)
    end
    menu.choice('Create a new type (rarely needed)') do |_|
      @@cli.ask('Write the new type to use', String) do |question|
        question.verify_match = true
        question.validate = STRING_VALUE_VALIDATOR
      end
    end
  end
end