Module: GHI::CLI::FormattingHelper

Included in:
Executable
Defined in:
lib/ghi/cli.rb

Instance Method Summary collapse

Instance Method Details

#action_format(value = nil) ⇒ Object



134
135
136
137
# File 'lib/ghi/cli.rb', line 134

def action_format(value = nil)
  key = "#{action.to_s.capitalize.sub(/e?$/, "ed")} issue #{number}"
  "#{key}: #{truncate(value.to_s, 78 - key.length)}"
end

#edit_format(issue) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ghi/cli.rb', line 100

def edit_format(issue)
  l = []
  l << issue.title if issue.title && !comment?
  l << ""
  l << issue.body  if issue.body  && !comment?
  if comment?
    l << "# Please enter your comment."
  else
    l << "# Please explain the issue. The first line will become the title."
  end
  l << "# Lines beginning '#' will be ignored; ghi aborts empty messages."
  l << "# All line breaks will be honored in accordance with GFM:"
  l << "#"
  l << "#   http://github.github.com/github-flavored-markdown"
  l << "#"
  l << "# On #{user}/#{repo}:"
  l << "#"
  l += show_format(issue, false).map { |line| "# #{line}" }
end

#indent(string, level = 4, first = level) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/ghi/cli.rb', line 145

def indent(string, level = 4, first = level)
  lines = string.scan(/.{0,#{79 - level}}(?:\s|\Z)/).map { |line|
    " " * level + line
  }
  lines.first.sub!(/^\s+/) {} if first != level
  lines
end

#list_format(issues, verbosity = nil) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ghi/cli.rb', line 88

def list_format(issues, verbosity = nil)
  unless issues.empty?
    if verbosity
      issues.map { |i| ["=" * 79] + show_format(i) }
    else
      issues.map { |i| "  #{i.number.to_s.rjust 3}: #{truncate(i.title, 72)}" }
    end
  else
    "none"
  end
end

#list_header(term = nil) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/ghi/cli.rb', line 80

def list_header(term = nil)
  if term
    "# #{state.to_s.capitalize} #{term.inspect} issues on #{user}/#{repo}"
  else
    "# #{state.to_s.capitalize} issues on #{user}/#{repo}"
  end
end

#show_format(issue, verbose = true) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ghi/cli.rb', line 120

def show_format(issue, verbose = true)
  l = []
  l << "      number:  #{issue.number}"                    if issue.number
  l << "       state:  #{issue.state}"                     if issue.state
  l << "       title:  #{indent(issue.title, 15, 0).join}" if issue.title
  l << "        user:  #{issue.user || GHI.}"
  l << "       votes:  #{issue.votes}"                     if issue.votes
  l << "  created at:  #{issue.created_at}"                if issue.created_at
  l << "  updated at:  #{issue.updated_at}"                if issue.updated_at
  return l unless verbose
  l << ""
  l += indent(issue.body)[0..-2]
end

#truncate(string, length) ⇒ Object



139
140
141
142
143
# File 'lib/ghi/cli.rb', line 139

def truncate(string, length)
  result = string.scan(/.{0,#{length - 3}}(?:\s|\Z)/).first.strip
  result << "..." if result != string
  result
end