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
- #ask_for_breaking ⇒ Object
- #ask_for_message ⇒ Object
- #ask_for_scope ⇒ Object
- #ask_for_summary ⇒ Object
- #ask_for_type ⇒ Object
Instance Method Details
#ask_for_breaking ⇒ Object
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_message ⇒ Object
95 96 97 98 99 |
# File 'lib/get/subcommand/commit/prompt.rb', line 95 def # 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_scope ⇒ Object
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 || .flow = :columns_down .prompt = 'Choose the scope of your commit: ' @@custom_scopes.each do |scope| .choice(scope.to_sym) end .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 .choice('None') { '' } end end |
#ask_for_summary ⇒ Object
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_type ⇒ Object
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 || .flow = :columns_down .prompt = 'Choose the type of your commit: ' DEFAULT_TYPES.union(@@custom_types).each do |type| .choice(type.to_sym) end .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 |