Module: PromptHandler
- Included in:
- Commit
- Defined in:
- lib/get/subcommand/commit/prompt.rb
Overview
Module for asking to the user information 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
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 MOD_REF.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. MOD_REF.cli.puts('The body of the commit (ends after 3 new lines):') MOD_REF.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 MOD_REF.cli.choose do || .flow = :columns_down .prompt = 'Choose the scope of your commit: ' MOD_REF.custom_scopes.each do |scope| .choice(scope.to_sym) end .choice('Create a new scope') do |_| MOD_REF.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 MOD_REF.cli.ask('The summary of the commit:') do |question| question.verify_match = true question.validate = STRING_VALUE_VALIDATOR end end |
#ask_for_type ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/get/subcommand/commit/prompt.rb', line 46 def ask_for_type extract_types_and_scopes MOD_REF.cli.choose do || .flow = :columns_down .prompt = 'Choose the type of your commit: ' DEFAULT_TYPES.union(MOD_REF.custom_types).each do |type| .choice(type.to_sym) end .choice('Create a new type (rarely needed)') do |_| MOD_REF.cli.ask('Write the new type to use', String) do |question| question.verify_match = true question.validate = STRING_VALUE_VALIDATOR end end end end |