66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/ctodo.rb', line 66
def run!
@options = {
:cs => COLOR_SETS[0],
:limit_text => false,
:show_source => false,
:show_assignee => false
}
@opts = OptionParser.new do |opts|
opts.banner = "Usage: todo.rb [options]"
opts.banner += "\nOptions:\n"
opts.on('--all', 'Show all todos (some providers limit to a reasonable number)') do @options[:all] = true end
opts.on('-l', '--limit-text', 'Limit todo text to fixed width') do @options[:limit_text] = true end
opts.on('-s', '--source', 'Show source of todos') do @options[:show_source] = true end
opts.on('-a', '--assignee', 'Show assignee of todos (when present)') do @options[:show_assignee] = true end
opts.on('-u CREDS', '--gh-user CREDS', 'Specify github credentials as USER:PASS') do |u| @options[:gh_creds] = u end
opts.on('-c CS', '--color-set CS', COLOR_SETS, "There are: #{COLOR_SETS.join(', ')}") do |cs|
@options[:cs] = cs if ['Fg', 'Bg', 'None'].include?(cs)
end
opts.on('-h', '-?', '--help', 'Display this screen') do
puts opts
exit
end
end
@opts.parse!
conf = load_config(File.join(ENV['HOME'], '.todo'))
conf[:cur_dir] = Dir.getwd
conf[:git_repo_dir] = find_git_repo(Dir.getwd)
conf[:hg_repo_dir] = find_hg_repo(Dir.getwd)
conf[:all] = @options[:all]
conf[:cs] = CTodo.const_get("#{@options[:cs]}ColorSet").new
ip = [
LocalFS.new(conf),
Github.new(conf),
Redmine.new(conf), Redmine.new(conf, 'red2'),
GoogleCodeProjectHosting.new(conf)
]
issues = []
ip.each do |ip| ip.get_issues(issues) end
if @options[:limit_text]
title_padding = MAX_TPAD
elsif issues.empty?
title_padding = MIN_TPAD
else
title_lens = issues.map { |i| i.title.length }
max_title_len = [title_lens.avg, title_lens.median].max
title_padding = (((max_title_len/TPAD_FAC.to_f).ceil)*TPAD_FAC).to_i.clamp(MIN_TPAD,MAX_TPAD)
end
issues.each do |i|
if @options[:limit_text] and i.title.length > title_padding
title = i.title[0,title_padding-3] + '...'
else
title = i.title
end
tag_list = i.tags.map { |t|
[ColorUtils.func4rgb(t.color, conf[:cs]).call, t.title, conf[:cs].rst].join
}
tag_list.push "@#{i.assignee}" if @options[:show_assignee] and not i.assignee.nil?
tag_list = (tag_list.empty? ? '' : format('(%s) ', tag_list.join(', ')))
if @options[:show_source] and !i.source.nil?
puts format("- %-#{title_padding}s %sin %s",
title, tag_list, i.source)
else
puts format("- %-#{title_padding}s %s",
title, tag_list)
end
end
end
|