rake_menu 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/rake_menu +5 -0
  2. data/lib/rake_menu.rb +200 -0
  3. metadata +82 -0
data/bin/rake_menu ADDED
@@ -0,0 +1,5 @@
1
+ #!ruby
2
+
3
+ require 'rake_menu'
4
+
5
+ RakeMenu::run
data/lib/rake_menu.rb ADDED
@@ -0,0 +1,200 @@
1
+ #!ruby
2
+
3
+ # = Rake Menu
4
+ #
5
+ # Displays a simple menu showing the tasks in a Rakefile.
6
+ #
7
+ # Instead of performing:
8
+ # (1) rake --tasks
9
+ # (2) rake <choosen-task>
10
+ #
11
+ # You now can type
12
+ #
13
+ # == Usage
14
+ # >> rake_menu
15
+ # and a menu is displayed showing the available tasks.
16
+ #
17
+ # Example:
18
+ # >>rake_menu
19
+ # 1. test -- Runs the tests
20
+ # 2. lib:rdoc -- Creates RDoc
21
+ # Choose Task:
22
+ #
23
+ # == Command Line Options
24
+ # You can provide the standard Rake command line options (like --trace).
25
+ #
26
+ # Additionally there are some defined only for Rake_Menu:
27
+ #
28
+ # <tt>--hide_default_tasks</tt>:: if given, then the tasks
29
+ # defined in the constant DEFAULT_TASKS
30
+ # are not displayed.
31
+ #
32
+ # == Hiding tasks from sub-rakefiles
33
+ # I am currently using rakefiles, that import other rakefiles (let's call em
34
+ # sub-rakefiles). As i don't want Rake_Menu to show the tasks of the
35
+ # sub-rakefiles but only those of the top-level rakefile I have included the
36
+ # possibility to exclude these.
37
+ #
38
+ # Let's have some code:
39
+ #
40
+ # $public_scope = [:mylib] unless $public_scope
41
+ # require 'yourlib/Rakefile' # defines namespace :yourlib
42
+ #
43
+ # namespace :mylib do
44
+ # ...
45
+ # end
46
+ #
47
+ # Setting $public_scope makes, that only tasks of scope (synonym namespace)
48
+ # :mylib are displayed while those of :yourlib are not. If you do not set
49
+ # $public_scope then all tasks are displayed.
50
+ #
51
+ # == Colorization
52
+ # is done using the text-highlight library.
53
+ #
54
+ # Author:: Tim Majunke (mailto:majunke@gmx.de)
55
+ # Copyright:: Copyright (c) 2008 Tim Majunke
56
+ # License:: Distributes under the same terms as Ruby
57
+ gem 'activesupport', '= 2.0.0'
58
+ require 'active_support/core_ext/enumerable'
59
+
60
+ # Menu
61
+ gem 'highline','= 1.4.0'
62
+ require 'highline/import'
63
+
64
+ # Colorizing Output
65
+ gem 'text-highlight','= 1.0.2'
66
+ require 'text/highlight'
67
+
68
+ $hl = Text::ANSIHighlighter.new
69
+ String.highlighter = $hl
70
+
71
+ begin
72
+ require 'rake'
73
+ rescue LoadError
74
+ require 'rubygems'
75
+ require 'rake'
76
+ end
77
+
78
+ module RakeMenu
79
+
80
+ DEFAULT_TASKS = %w|pkg clobber gem package default repackage|
81
+
82
+ # Colorizing
83
+ module Colorizer
84
+
85
+ module_function
86
+
87
+ # Called for colorizing the displayed task name
88
+ def colorize_task task
89
+ if task.name =~ /test$/
90
+ #task.name_with_args.green
91
+ task.name_with_args
92
+ else
93
+ task.name_with_args
94
+ end
95
+ end
96
+
97
+ # Called for colorizing the displayed task description
98
+ def colorize_desc task, max_column
99
+ truncate(task.comment.gsub("\n",''), max_column).yellow
100
+ end
101
+
102
+ # From rake.rb
103
+ def truncate(string, width)
104
+ if string.length <= width
105
+ string
106
+ else
107
+ ( string[0, width-3] || "" ) + "..."
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ def self.parse_args
114
+ # Ausblenden der Default Tasks
115
+ if $*.include?("--hide-default-tasks")
116
+ # Rake kennt dieses Option nicht, daher m�ssen wir sie hier entfernen
117
+ $*.delete "--hide-default-tasks"
118
+ @hide_default_tasks = true
119
+ end
120
+ end
121
+
122
+ def self.rakify
123
+ app = Rake.application
124
+
125
+ app.standard_exception_handling do
126
+ app.init
127
+ app.options.silent = true # sonst schreibt rake '(in /ws/rake_menu/lib)'
128
+ app.load_rakefile
129
+ end
130
+
131
+ app
132
+ end
133
+
134
+ def self.filter_public_tasks tasks
135
+ # Filtern der Tasks, die angezeigt werden sollen
136
+ tasks.select do |task|
137
+ if $public_scope
138
+ task.comment and task.scope == $public_scope
139
+ else
140
+ task.comment
141
+ end
142
+ end
143
+ end
144
+
145
+ def self.hide_default_tasks tasks
146
+ # Ausblenden der Default Tasks
147
+ if @hide_default_tasks
148
+ tasks = tasks.reject do |task|
149
+ DEFAULT_TASKS.any? do |default|
150
+ task.name =~ /#{default}$/
151
+ end
152
+ end
153
+ end
154
+ tasks
155
+ end
156
+
157
+ def self.show_menu tasks
158
+ width = tasks.map do |t|
159
+ Colorizer::colorize_task(t).length
160
+ end.max || 10
161
+
162
+ maximale_zeilenbreite = 120
163
+ max_column = maximale_zeilenbreite - 4 - width - 7
164
+
165
+ choose do |menu|
166
+ menu.prompt = "Choose Task:"
167
+
168
+ tasks.each_with_index do |task, i|
169
+
170
+ indent = i > 8 ? 0 : 1
171
+
172
+ task_name = Colorizer::colorize_task(task)
173
+ task_desc = Colorizer::colorize_desc(task, max_column)
174
+ display = "%-#{indent}s%-#{width}s -- %s" % [nil, task_name, task_desc ]
175
+ menu.choice(display) do
176
+ #puts "Running task #{i} => '#{tasks[i].name_with_args}'"
177
+ tasks[i].invoke
178
+ end
179
+ #puts task.name, task.comment, task.full_comment #:name, :comment, :full_comment
180
+ end
181
+
182
+ end
183
+ end
184
+
185
+ def self.run
186
+ parse_args
187
+ app = rakify
188
+ tasks = filter_public_tasks app.tasks
189
+ tasks = hide_default_tasks tasks
190
+ show_menu tasks
191
+ end
192
+
193
+ end
194
+
195
+ if $0 == __FILE__ or $0 =~ /rdebug-ide/
196
+ # Dir.chdir 'lib/rake_menu/rake' do
197
+ RakeMenu::run
198
+ # end
199
+ end
200
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake_menu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tim Majunke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-15 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: highline
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: text-highlight
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.2
44
+ version:
45
+ description: Displays a simple menu showing the tasks in a Rakefile.
46
+ email: majunke@gmx.de
47
+ executables:
48
+ - rake_menu
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - lib/rake_menu.rb
55
+ has_rdoc: false
56
+ homepage: none
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.3.0
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: Simple Interface to rake, showing all tasks in a menu
81
+ test_files: []
82
+