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 = " \#{color? ? del_msg.light_magenta : del_msg}\n \#{format_branch branch: sprint_data[:branch], color: :red}\n \#{format_branch branch: sprint_data[:dev_branch], color: :red}\n MSG\n\n git.branch(sprint_data[:dev_branch]).delete\n git.branch(sprint_data[:branch]).delete\n\n say msg\n\n log.debug { 'Finished `delete` command...' }\nrescue Git::GitExecuteError => e\n die \"[Error] \#{e.class}\\n\#{e.message}\"\nend\n" |
#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...' } = " Name:\n git sprint\n\n Summary:\n a git plugin for sprint related commands\n MSG\n\n usage = capture_std_out { super }\n\n output = if cmd.nil? # print banner\n if color?\n \"\#{banner}\\n\#{usage}\".rainbow\n else\n \"\#{banner}\\n\#{usage}\"\n end\n else\n color? ? usage.rainbow : usage\n end\n\n if options[:pager] && output&.split(\"\\n\")&.size.send(:>, 30)\n pager = ENV['PAGER'] || 'less'\n temp_file = Tempfile.new\n temp_file.puts output\n temp_file.close\n\n system \"\#{pager} \#{temp_file.path}\"\n else\n say output\n end\n\n log.debug { 'Finished `help` command.' }\nend\n" |
#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 " \#{color? ? msg.light_magenta : msg}\n \#{format_branch branch: sprint_data[:branch], color: :green}\n \#{format_branch branch: sprint_data[:dev_branch], color: :green}\n MSG\n\n log.debug { 'Finished `start` command...' }\nrescue Git::GitExecuteError => e\n die \"[Error] \#{e.class}\\n\#{e.message}\"\nend\n" |
#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 |