5
6
7
8
9
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
47
48
49
|
# File 'lib/make_menu/builder.rb', line 5
def self.build(makefile, )
File.open(makefile, 'r') do |file|
option_number = 1
current_group = nil
file.each_line do |line|
if line.start_with? '###'
group_title = line.gsub(/###\s+/, '').strip
current_group = .add_group MenuItemGroup.new(group_title.color(.group_title_color))
elsif line.match(/^[a-zA-Z_-]+:.*?## .*$$/)
target = line.split(':').first.strip
description = line.split('##').last.strip
next if target == 'menu'
current_group ||= .add_group MenuItemGroup.new('Commands'.color(.group_title_color))
.add_item current_group.add_item(MenuItem.new(option_number, target, description))
option_number += 1
end
end
if option_number == 1
puts
puts 'No annotated targets found!'.red.bold
puts
puts 'Expecting something like this....'
puts " #{'my_target:'.cyan} #{'## Do some things'.yellow}"
puts
exit 1
end
end
rescue Errno::ENOENT => _e
puts
puts 'No Makefile!'.red.bold
puts
puts "File '#{makefile}' could not be found.".yellow
puts
exit 1
end
|