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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc7cc20145ab71318914fd1b32c00da9e20337c548128a4f6cc8f84c753c5c6d
4
- data.tar.gz: f3f5224f1879623d6977e7bb6dec008c0c545ff15f4b8aef2ff4db99118310b7
3
+ metadata.gz: 73bdc3fd5ddcd1b81d30090501aaca35359319f9c3b02be2683f63a613ea7995
4
+ data.tar.gz: ad8dffffc25cc90458a1edc1eea76a760181e65b905a96e8a0338e3eb3a8df64
5
5
  SHA512:
6
- metadata.gz: 8c34001ed3bcaa9de37038d2730a6523203c8519cd99b408469a2feaa37825bb2c03e449e245f82504df78fc473aae97a2b7bb60787164de485d79f10361d881
7
- data.tar.gz: 18e260dffd57d776ed3518968c92cd7078a8d074c9649a2f4bfd8075b78f57d0b512dc036808cf86e7a47d5e51f11cfc3d7241508af72e5a535adf2b675b694e
6
+ metadata.gz: 3550f1dbe5182179c1fb6ce75e0a4b594acb68e509af7d669d984c7b481b17edb0041f7108a89dca1e89cd2170d548723e6a635d71ffb1bf8526eff1f12611ea
7
+ data.tar.gz: 5d4d46df1f6943fe413b8c5adffc4ccf05e40e8575a7ca1498f6f19014dbbe508c504bfae0d40ec3023de90c33e6014e9b5db80a3339191028a764c2a090c64b
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.1
4
+
5
+ - `branding_header`, `prompt_question`, and `task_formatter` block options
6
+
3
7
  ## 0.2.0
4
8
 
5
9
  - Optimized performance for JRuby
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.0
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
- # Run TUI (recommended for general use)
19
- def run
20
- instance.run
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
- # Initialize a new TUI object
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
- # Run TUI
41
- def run
42
- version = File.read(File.expand_path('../../../../../VERSION', __FILE__)).strip
43
- puts "== rake-tui version #{version} =="
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
- unless @rake_task_lines&.detect {|l| l.start_with?('rake ')}
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
- rake_task_lines = @rake_task_lines.map do |line|
63
- bound = TTY::Screen.width - 6
64
- line.size <= bound ? line : "#{line[0..(bound - 3)]}..."
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
- rake_task_with_args = rake_task_line.split('#').first.strip.split[1]
78
- rake_task, rake_task_arg_names = rake_task_with_args.sub(']', '').split('[')
79
- rake_task_arg_names = rake_task_arg_names&.split(',').to_a
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake-tui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - andy_maleh