class Rlt::Commands::Cmt
Constants
- CONF_BODY_TEMPLATE
- CONF_PRE
- CONF_SUBJECT_TEMPLATE
Public Class Methods
adjust_body_template(body, config, branch_name)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 95 def self.adjust_body_template(body, config, branch_name) template = config[CONF_BODY_TEMPLATE] return body if config.nil? || template.nil? ERB.new(template).result binding end
adjust_subject_template(subject, config, branch_name)
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/rlt/commands/cmt.rb, line 89 def self.adjust_subject_template(subject, config, branch_name) template = config[CONF_SUBJECT_TEMPLATE] return subject if config.nil? || template.nil? ERB.new(template).result binding end
ask_and_commit(add_all, config)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 31 def self.ask_and_commit(add_all, config) branch_name = Utils::GitUtil.current_branch_name Utils::Logger.info "Committing to '#{branch_name}'" (subject, body) = subject_and_body(config, branch_name) Utils::GitUtil.add_all if add_all commit(subject, body) end
ask_body()
click to toggle source
# File lib/rlt/commands/cmt.rb, line 71 def self.ask_body puts 'Body: (Insert empty line to finish)' lines = ask_multiline_until_done('>', :magenta) lines.join("\n") end
ask_multiline_until_done(message, active_color)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/rlt/commands/cmt.rb, line 78 def self.ask_multiline_until_done(message, active_color) lines = [] loop do line = TTY::Prompt.new.ask(message, active_color: active_color) break if line.nil? lines << line end lines end
ask_subject()
click to toggle source
# File lib/rlt/commands/cmt.rb, line 49 def self.ask_subject prompt = TTY::Prompt.new subject = prompt.ask('Subject:', active_color: :magenta) do |q| q.required true end garden_subject(subject) end
commit(subject, body)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 45 def self.commit(subject, body) Utils::GitUtil.commit_with_long_message("#{subject}\n\n#{body}".strip) end
first_letter_upcase(str)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 67 def self.first_letter_upcase(str) str[0].upcase + str[1..-1] end
garden_subject(subject)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 57 def self.garden_subject(subject) subject = remove_period(subject) subject = first_letter_upcase(subject) subject end
print_abort_due_to_pre_script_failure()
click to toggle source
# File lib/rlt/commands/cmt.rb, line 20 def self.print_abort_due_to_pre_script_failure Utils::Logger.error 'Aborted due to the pre-script failed.' end
remove_period(str)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 63 def self.remove_period(str) str.gsub(/\.$/, '') end
run(config, add_all)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 14 def self.run(config, add_all) result = run_pre_script_if_any(config) return print_abort_due_to_pre_script_failure unless result ask_and_commit(add_all, config) end
run_pre_script_if_any(config)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 24 def self.run_pre_script_if_any(config) return true if config[CONF_PRE].nil? Utils::Logger.info 'Executing pre-script:' Utils::Logger.desc " #{config[CONF_PRE]}" Utils::Shell.new.run_safely config[CONF_PRE] end
subject_and_body(config, branch_name)
click to toggle source
# File lib/rlt/commands/cmt.rb, line 39 def self.subject_and_body(config, branch_name) subject = adjust_subject_template(ask_subject, config, branch_name) body = adjust_body_template(ask_body, config, branch_name) [subject, body] end