Class: GitSprint::CLI
- Inherits:
-
Thor
- Object
- Thor
- GitSprint::CLI
- Includes:
- CaptureOutput, GitSprintLogger
- Defined in:
- lib/git-sprint/cli.rb,
lib/git-sprint/cli/help.rb,
lib/git-sprint/cli/list.rb,
lib/git-sprint/cli/start.rb,
lib/git-sprint/cli/delete.rb,
lib/git-sprint/cli/version.rb
Overview
Main command class
@todo: use config for colors. ‘git.config.has_key? ’sprint.colors.branch’‘
Class Method Summary collapse
-
.exit_on_failure? ⇒ Boolean
Exit non-zero when a command is missing a required argument, etc.
Instance Method Summary collapse
- #delete ⇒ Object
-
#help(cmd = nil, *args) ⇒ Object
Get help for a command.
- #list ⇒ Object
- #start ⇒ Object
- #version ⇒ Object
Methods included from CaptureOutput
Methods included from GitSprintLogger
Class Method Details
.exit_on_failure? ⇒ Boolean
Exit non-zero when a command is missing a required argument, etc.
28 29 30 |
# File 'lib/git-sprint/cli.rb', line 28 def self.exit_on_failure? true end |
Instance Method Details
#delete ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/git-sprint/cli/delete.rb', line 4 def delete handle_debug_option! sprint_data = prompt_for_sprint_vars! log.debug { 'Running `delete` command...' } del_msg = 'deleted sprint branches:' msg = <<~MSG #{color? ? del_msg.light_magenta : del_msg} #{format_branch branch: sprint_data[:branch], color: :red} #{format_branch branch: sprint_data[:dev_branch], color: :red} MSG git.branch(sprint_data[:dev_branch]).delete git.branch(sprint_data[:branch]).delete say msg log.debug { 'Finished `delete` command...' } rescue Git::GitExecuteError => e die "[Error] #{e.class}\n#{e.}" end |
#help(cmd = nil, *args) ⇒ Object
Get help for a command.
This command is generated by thor, so we just add a message to the start when ‘git sprint` or `git sprint help` is called.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/git-sprint/cli/help.rb', line 10 def help cmd = nil, *args handle_debug_option! log.debug { 'Running `help` command...' } = <<~MSG Name: git sprint Summary: a git plugin for sprint related commands MSG usage = capture_std_out { super } output = if cmd.nil? # print banner if color? "#{}\n#{usage}".rainbow else "#{}\n#{usage}" end else color? ? usage.rainbow : usage end if [:pager] && output&.split("\n")&.size.send(:>, 30) pager = ENV['PAGER'] || 'less' temp_file = Tempfile.new temp_file.puts output temp_file.close system "#{pager} #{temp_file.path}" else say output end log.debug { 'Finished `help` command.' } end |
#list ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/git-sprint/cli/list.rb', line 4 def list handle_debug_option! log.debug { 'Running `list` command...' } sprint_branches = git.branches .local .map(&:name) .select { |b| b.include? 'sprint' } die 'no sprint branches!' if sprint_branches.empty? msg = 'sprint branches:' say color? ? msg.light_magenta : msg sprint_branches.each do |branch| say format_branch(branch: branch, color: :green) end log.debug { 'Finished `list` command...' } end |
#start ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/git-sprint/cli/start.rb', line 4 def start handle_debug_option! sprint_data = prompt_for_sprint_vars! log.debug { 'Running `start` command...' } git.branch(sprint_data[:dev_branch]).create git.branch(sprint_data[:branch]).create msg = 'created new branches' say <<~MSG #{color? ? msg.light_magenta : msg} #{format_branch branch: sprint_data[:branch], color: :green} #{format_branch branch: sprint_data[:dev_branch], color: :green} MSG log.debug { 'Finished `start` command...' } rescue Git::GitExecuteError => e die "[Error] #{e.class}\n#{e.}" end |
#version ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/git-sprint/cli/version.rb', line 5 def version log.debug { 'Running `version` command...' } version = GitSprint::VERSION if color? say "git sprint version #{version.light_green}" else say "git sprint version #{version}" end log.debug { 'Finished `version` command.' } end |