On Mon, Feb 25, 2008 at 1:08 PM, Jim Weirich <[EMAIL PROTECTED]> wrote:
>
> On Feb 25, 2008, at 3:55 PM, Jason LaPier wrote:
> > This is an extremely trivial point, so don't spend too much time on it
> > :) I understand the rationale behind the truncation of task
> > descriptions in 'rake -T' but I find the 80 column limit a little too
> > condensed for my personal tastes. I whipped up a rake task that
> > displays tasks and allows me to specify my column limit with an
> > environment variable. Something like:
> > $ export RAKE_DESC_COLS=180
> > $ rake t
> > $ rake t[some-pattern]
> >
> > The rake task is detailed here:
> > http://offtheline.net/2008/2/24/rake-and-truncated-task-descriptions
> > If anyone thinks they might find this useful, I'd be willing to create
> > a patch (to work with '-T' rather than a task named 't'). Let me know
> > if you'd prefer using an environment variable or another command-line
> > switch. Personally, I like the environment variable because I can
> > stick it in my .bashrc and have different column width depending on
> > what computer I'm in front of.
>
> I would accept a patch that allowed an environment variable to set the
> column width for -T. Don't forget unit tests.
>
> --
> -- Jim Weirich
> -- [EMAIL PROTECTED]
>
Cool, thanks. Patch file attached (test included).
- Jason L.
--
My Rails and Linux Blog: http://offtheline.net
Index: test/test_application.rb
===================================================================
--- test/test_application.rb (revision 639)
+++ test/test_application.rb (working copy)
@@ -20,6 +20,7 @@
def setup
@app = Rake::Application.new
@app.options.rakelib = []
+ ENV['RAKE_DESC_COLS'] = nil
end
def test_constant_warning
@@ -37,6 +38,17 @@
assert_match(/^rake t/, out)
assert_match(/# COMMENT/, out)
end
+
+ def test_display_tasks_with_set_column_width
+ ENV['RAKE_DESC_COLS'] = '120'
+ @app.options.show_task_pattern = //
+ @app.last_description = 'a'*100
+ @app.define_task(Rake::Task, "t")
+ out = capture_stdout do @app.instance_eval { display_tasks_and_comments } end
+ assert_equal 'rake t # '.size + 100, out.strip.size
+ assert_match(/^rake t/, out)
+ assert_match(/# #{'a'*100}/, out)
+ end
def test_display_tasks_with_long_comments
@app.options.show_task_pattern = //
Index: lib/rake.rb
===================================================================
--- lib/rake.rb (revision 639)
+++ lib/rake.rb (working copy)
@@ -2011,7 +2011,8 @@
end
else
width = displayable_tasks.collect { |t| t.name_with_args.length }.max || 10
- max_column = 80 - name.size - width - 7
+ cols = ENV['RAKE_DESC_COLS'] ? ENV['RAKE_DESC_COLS'].to_i : 80
+ max_column = cols - name.size - width - 7
displayable_tasks.each do |t|
printf "#{name} %-#{width}s # %s\n",
t.name_with_args, truncate(t.comment, max_column)
_______________________________________________
Rake-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rake-devel