Top Level Namespace
Defined Under Namespace
Modules: Git, Github, Plugins Classes: OctokitWrapper
Constant Summary collapse
- HIGHLIGHT =
"\033[31m"- HIGHLIGHT_OFF =
"\033[0m"
Instance Method Summary collapse
-
#confirm(question) ⇒ Object
Repeatedly prints out a y/n question until a y or n is input.
- #die(message = '') ⇒ Object
- #display_feature_help(command = nil, message = nil) ⇒ Object
- #display_help(args) ⇒ Object
- #esc(str) ⇒ Object
- #fail_on_local_changes ⇒ Object
- #get_branch_name_from_number(num) ⇒ Object
- #highlight(str) ⇒ Object
-
#log_command(command) ⇒ Object
Write the given string to the git-dir specific git-scripts command-log.
-
#optional_pull ⇒ Object
If the commandline arguments contain ‘–pull’, perform a feature pull.
-
#require_argument(program, command = nil, min = 2, max = 2) ⇒ Object
Prints out an error and the appropriate help if there is not exactly one command-line argument.
- #wrap_text(txt, col = 80) ⇒ Object
Instance Method Details
#confirm(question) ⇒ Object
Repeatedly prints out a y/n question until a y or n is input
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/helpers.rb', line 90 def confirm(question) loop do print(question) print(" (y/n): ") STDOUT.flush s = STDIN.gets exit if s == nil s.chomp! return true if s == 'y' return false if s == 'n' end end |
#die(message = '') ⇒ Object
104 105 106 |
# File 'lib/helpers.rb', line 104 def die( = '') abort wrap_text() end |
#display_feature_help(command = nil, message = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/helpers.rb', line 11 def display_feature_help(command = nil, = nil) display_help( :script_name => "Git Feature Branch Helper", :commands => { :list => "feature list [-v]", :url => "feature url [name-of-feature]", :start => "feature start name-of-feature", :switch => "feature switch (name-of-feature | -n number-of-feature) [options]", :finish => "feature finish [name-of-feature]", :'finish-issue' => "feature finish-issue issue-number", :merge => "feature merge (name-of-feature | -n number-of-feature)", :pull => "feature pull", :prune => "feature prune <local | origin> <preview | clean>", :status => "feature status", :stashes => "feature stashes [-v]", :'github-test' => "feature github-test" }, :command_name => 'feature', :command => command, :message => ) end |
#display_help(args) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/helpers.rb', line 34 def display_help(args) command = args[:command] = args[:message] script_name = args[:script_name] highlighted_commands = args[:commands].map do |name, desc| help_line = " #{name.to_s.ljust(8)} #{desc}" if name == command HIGHLIGHT + help_line + HIGHLIGHT_OFF else help_line end end if puts HIGHLIGHT + "Error: " + HIGHLIGHT_OFF + puts puts end die <<HELP #{script_name} usage: #{highlighted_commands.join("\n")} arguments: name-of-#{args[:command_name]}: letters, numbers, and dashes Look at the source to discover what each of these commands does. HELP end |
#esc(str) ⇒ Object
144 145 146 |
# File 'lib/helpers.rb', line 144 def esc(str) str.shellescape end |
#fail_on_local_changes ⇒ Object
4 5 6 7 8 9 |
# File 'lib/helpers.rb', line 4 def fail_on_local_changes if Git::has_uncommitted_changes die "Cannot perform this action with a dirty working tree; " + "please stash your changes with 'git stash save \"Some message\"'." end end |
#get_branch_name_from_number(num) ⇒ Object
112 113 114 115 116 |
# File 'lib/helpers.rb', line 112 def get_branch_name_from_number(num) octokit = Github::api return octokit.pull_request(Github::get_github_repo, num).head.ref end |
#highlight(str) ⇒ Object
108 109 110 |
# File 'lib/helpers.rb', line 108 def highlight(str) return HIGHLIGHT + str + HIGHLIGHT_OFF end |
#log_command(command) ⇒ Object
Write the given string to the git-dir specific git-scripts command-log
127 128 129 130 131 132 133 |
# File 'lib/helpers.rb', line 127 def log_command(command) require 'time' filename = File.join(Git.git_dir, "git-scripts.log") log = File.open(filename, "a") log.puts "#{Time.now.iso8601}: #{command}" log.close end |
#optional_pull ⇒ Object
If the commandline arguments contain ‘–pull’, perform a feature pull
138 139 140 141 142 |
# File 'lib/helpers.rb', line 138 def optional_pull if ARGV.include?("--pull") puts %x(feature pull) end end |
#require_argument(program, command = nil, min = 2, max = 2) ⇒ Object
Prints out an error and the appropriate help if there is not exactly one command-line argument
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/helpers.rb', line 73 def require_argument(program, command = nil, min = 2, max = 2) help = lambda do |msg| display_feature_help(command, msg) end if (ARGV.length > max) help.call "Too many arguments. This command accepts only #{max} arguments." end if (ARGV.length < min) help.call "Missing argument. This command requires exactly #{min} arguments." end end |
#wrap_text(txt, col = 80) ⇒ Object
118 119 120 121 122 |
# File 'lib/helpers.rb', line 118 def wrap_text(txt, col = 80) txt.gsub( /(.{1,#{col}})(?: +|$)\n?|(.{#{col}})/, "\\1\\3\n") end |