rake-tui 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +117 -0
- data/VERSION +1 -1
- data/lib/rake-tui/ext/rake/tui.rb +44 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73bdc3fd5ddcd1b81d30090501aaca35359319f9c3b02be2683f63a613ea7995
|
4
|
+
data.tar.gz: ad8dffffc25cc90458a1edc1eea76a760181e65b905a96e8a0338e3eb3a8df64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3550f1dbe5182179c1fb6ce75e0a4b594acb68e509af7d669d984c7b481b17edb0041f7108a89dca1e89cd2170d548723e6a635d71ffb1bf8526eff1f12611ea
|
7
|
+
data.tar.gz: 5d4d46df1f6943fe413b8c5adffc4ccf05e40e8575a7ca1498f6f19014dbbe508c504bfae0d40ec3023de90c33e6014e9b5db80a3339191028a764c2a090c64b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -93,6 +93,123 @@ Rake::TUI.instance(Rake::TUI.new(tasks))
|
|
93
93
|
Rake::TUI.run # this now displays the specified task list
|
94
94
|
```
|
95
95
|
|
96
|
+
## Options
|
97
|
+
|
98
|
+
### `branding_header`
|
99
|
+
|
100
|
+
The default branding header looks like this (from `Rake::TUI::BRANDING_HEADER_DEFAULT`):
|
101
|
+
|
102
|
+
```
|
103
|
+
== rake-tui version 0.2.1 ==
|
104
|
+
```
|
105
|
+
|
106
|
+
It may be customized by passing in the `branding_header` option (removed when set to `nil`).
|
107
|
+
|
108
|
+
Example:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
Rake::TUI.run(branding_header: '== Glimmer (Ruby Desktop Development GUI Library) ==')
|
112
|
+
```
|
113
|
+
|
114
|
+
Output:
|
115
|
+
|
116
|
+
```
|
117
|
+
== Glimmer (Ruby Desktop Development GUI Library) ==
|
118
|
+
```
|
119
|
+
|
120
|
+
### `prompt_question`
|
121
|
+
|
122
|
+
The prompt question is the text that shows up before the help message and looks like this (from `Rake::TUI::PROMPT_QUESTION_DEFAULT`):
|
123
|
+
|
124
|
+
```
|
125
|
+
Choose a Rake task:
|
126
|
+
```
|
127
|
+
|
128
|
+
It may be customized by passing in the `prompt_question` option:
|
129
|
+
|
130
|
+
Example:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
Rake::TUI.run(prompt_question: 'Select a Glimmer task:')
|
134
|
+
```
|
135
|
+
|
136
|
+
Output:
|
137
|
+
|
138
|
+
```
|
139
|
+
Choose a Rake task: (Press ↑/↓ arrow to move, Enter to select and letters to filter)
|
140
|
+
```
|
141
|
+
|
142
|
+
### `task_formatter` block
|
143
|
+
|
144
|
+
The task formatter (default: `Rake::TUI::TASK_FORMATTER_DEFAULT`) is responsible for formatting
|
145
|
+
tasks into task lines presented as choices to the user.
|
146
|
+
|
147
|
+
It receives `task` and `tasks` list as options.
|
148
|
+
|
149
|
+
For example, by default, it prints the same standard output you see from running `rake -T`:
|
150
|
+
|
151
|
+
```
|
152
|
+
rake build # Build gem into pkg/
|
153
|
+
rake clean # Remove any temporary products
|
154
|
+
rake clobber # Remove any generated files
|
155
|
+
rake clobber_rdoc # Remove RDoc HTML files
|
156
|
+
rake console[script] # Start IRB with all runtime dependencies loaded
|
157
|
+
rake gemcutter:release # Release gem to Gemcutter
|
158
|
+
rake gemspec # Generate and validate gemspec
|
159
|
+
rake gemspec:debug # Display the gemspec for debugging purposes, as juwelier knows it (not from the filesystem)
|
160
|
+
rake gemspec:generate # Regenerate the gemspec on the filesystem
|
161
|
+
‣ rake gemspec:release # Regenerate and validate gemspec, and then commits and pushes to git
|
162
|
+
rake gemspec:validate # Validates the gemspec on the filesystem
|
163
|
+
rake git:release # Tag and push release to git
|
164
|
+
rake install # Build and install gem using `gem install`
|
165
|
+
rake rdoc # Build RDoc HTML files
|
166
|
+
rake release # Release gem
|
167
|
+
rake rerdoc # Rebuild RDoc HTML files
|
168
|
+
rake simplecov # Code coverage detail
|
169
|
+
rake spec # Run RSpec code examples
|
170
|
+
rake version # Displays the current version
|
171
|
+
rake version:bump:major # Bump the major version by 1
|
172
|
+
rake version:bump:minor # Bump the a minor version by 1
|
173
|
+
rake version:bump:patch # Bump the patch version by 1
|
174
|
+
rake version:write # Writes out an explicit version
|
175
|
+
```
|
176
|
+
|
177
|
+
However, it can be customized by passing in a `task_formatter` block.
|
178
|
+
|
179
|
+
Example:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
Rake::TUI.new.run { |task, tasks| task.name_with_args }
|
183
|
+
```
|
184
|
+
|
185
|
+
Output:
|
186
|
+
|
187
|
+
```
|
188
|
+
build
|
189
|
+
clean
|
190
|
+
clobber
|
191
|
+
clobber_rdoc
|
192
|
+
console[script]
|
193
|
+
gemcutter:release
|
194
|
+
gemspec
|
195
|
+
gemspec:debug
|
196
|
+
gemspec:generate
|
197
|
+
gemspec:release
|
198
|
+
gemspec:validate
|
199
|
+
git:release
|
200
|
+
install
|
201
|
+
rdoc
|
202
|
+
‣ release
|
203
|
+
rerdoc
|
204
|
+
simplecov
|
205
|
+
spec
|
206
|
+
version
|
207
|
+
version:bump:major
|
208
|
+
version:bump:minor
|
209
|
+
version:bump:patch
|
210
|
+
version:write
|
211
|
+
```
|
212
|
+
|
96
213
|
## TODO
|
97
214
|
|
98
215
|
[TODO.md](TODO.md)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -5,6 +5,16 @@ Rake::TaskManager.record_task_metadata = true
|
|
5
5
|
|
6
6
|
module Rake
|
7
7
|
class TUI
|
8
|
+
VERSION = File.read(File.expand_path('../../../../../VERSION', __FILE__)).strip
|
9
|
+
BRANDING_HEADER_DEFAULT = "== rake-tui version #{VERSION} =="
|
10
|
+
PROMPT_QUESTION_DEFAULT = "Choose a Rake task: "
|
11
|
+
TASK_FORMATTER_DEFAULT = lambda do |task, tasks|
|
12
|
+
max_task_size = tasks.map(&:name_with_args).map(&:size).max + 1
|
13
|
+
line = "rake #{task.name_with_args.ljust(max_task_size)} # #{task.comment}"
|
14
|
+
bound = TTY::Screen.width - 6
|
15
|
+
line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
|
16
|
+
end
|
17
|
+
|
8
18
|
class << self
|
9
19
|
# Singleton instance (if argument is specified, it is used to set instance)
|
10
20
|
def instance(tui=nil)
|
@@ -15,13 +25,22 @@ module Rake
|
|
15
25
|
end
|
16
26
|
end
|
17
27
|
|
18
|
-
#
|
19
|
-
|
20
|
-
|
28
|
+
# Runs TUI (recommended for general use)
|
29
|
+
#
|
30
|
+
# Optionally takes a `branding_header` to customize the branding header or take it off when set to `nil`.
|
31
|
+
#
|
32
|
+
# Optionally takes a `prompt_question` to customize the question for selecting a rake task.
|
33
|
+
#
|
34
|
+
# Optionally pass a task_formatter mapping block to
|
35
|
+
# transform every rake task line into a different format
|
36
|
+
# e.g. Rake::TUI.new.run { |task, tasks| task.name_with_args }
|
37
|
+
# This makes tasks show up without `rake` prefix or `# description` suffix
|
38
|
+
def run(branding_header: BRANDING_HEADER_DEFAULT, prompt_question: PROMPT_QUESTION_DEFAULT, &task_formatter)
|
39
|
+
instance.run(branding_header: branding_header, prompt_question: prompt_question, &task_formatter)
|
21
40
|
end
|
22
41
|
end
|
23
42
|
|
24
|
-
#
|
43
|
+
# Initializes a new TUI object
|
25
44
|
def initialize(tasks=Rake.application.tasks)
|
26
45
|
if tasks.empty?
|
27
46
|
Rake.application.init
|
@@ -29,20 +48,23 @@ module Rake
|
|
29
48
|
tasks = Rake.application.tasks
|
30
49
|
end
|
31
50
|
|
32
|
-
tasks = tasks.reject {|task| task.comment.nil?}
|
33
|
-
|
34
|
-
max_task_size = !tasks.empty? && (tasks.map(&:name_with_args).map(&:size).max + 1)
|
35
|
-
@rake_task_lines = tasks.map do |task|
|
36
|
-
"rake #{task.name_with_args.ljust(max_task_size)} # #{task.comment}"
|
37
|
-
end
|
51
|
+
@tasks = tasks.reject {|task| task.comment.nil?}
|
38
52
|
end
|
39
53
|
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
54
|
+
# Runs TUI
|
55
|
+
#
|
56
|
+
# Optionally takes a `branding_header` to customize the branding header or take it off when set to `nil`.
|
57
|
+
#
|
58
|
+
# Optionally takes a `prompt_question` to customize the question for selecting a rake task.
|
59
|
+
#
|
60
|
+
# Optionally takes a `task_formatter` mapping block to
|
61
|
+
# transform every rake task line into a different format
|
62
|
+
# e.g. Rake::TUI.new.run { |task, tasks| task.name_with_args }
|
63
|
+
# This makes tasks show up without `rake` prefix or `# description` suffix
|
64
|
+
def run(branding_header: BRANDING_HEADER_DEFAULT, prompt_question: PROMPT_QUESTION_DEFAULT, &task_formatter)
|
65
|
+
puts branding_header unless branding_header.nil?
|
44
66
|
|
45
|
-
|
67
|
+
if @tasks.empty?
|
46
68
|
puts "No Rake tasks found!"
|
47
69
|
puts "Exiting..."
|
48
70
|
exit(0)
|
@@ -58,12 +80,10 @@ module Rake
|
|
58
80
|
exit(0)
|
59
81
|
end
|
60
82
|
|
61
|
-
begin
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
rake_task_line = prompt.select("Choose a Rake task: ", rake_task_lines, cycle: true, per_page: [TTY::Screen.height - 5, 1].max, filter: true, show_help: :always, help: "(Press ↑/↓ arrow to move, Enter to select, CTRL+Enter to run without arguments, and letters to filter)") do |list|
|
83
|
+
begin
|
84
|
+
task_formatter ||= TASK_FORMATTER_DEFAULT
|
85
|
+
rake_task_lines = @tasks.map {|task, tasks| task_formatter.call(task, @tasks)}
|
86
|
+
rake_task_line = prompt.select(prompt_question, rake_task_lines, cycle: true, per_page: [TTY::Screen.height - 5, 1].max, filter: true, show_help: :always) do |list|
|
67
87
|
list.singleton_class.define_method(:keyspace) do |event|
|
68
88
|
return unless filterable?
|
69
89
|
|
@@ -74,9 +94,9 @@ module Rake
|
|
74
94
|
end
|
75
95
|
end
|
76
96
|
|
77
|
-
|
78
|
-
rake_task
|
79
|
-
rake_task_arg_names =
|
97
|
+
selected_task = @tasks[rake_task_lines.index(rake_task_line)]
|
98
|
+
rake_task = selected_task.name
|
99
|
+
rake_task_arg_names = selected_task.arg_names
|
80
100
|
rake_task_arg_values = rake_task_arg_names.map do |rake_task_arg_name|
|
81
101
|
prompt.ask("Enter [#{rake_task_arg_name}] (default=nil):")
|
82
102
|
end
|