From 07d1b32306de0578a929d7ffba2dc1a5a752f4f9 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 7 Aug 2015 07:01:20 -0700 Subject: [PATCH] Add Rake Only Lists Tasks With Descriptions as a ruby til. --- README.md | 1 + ...rake-only-lists-tasks-with-descriptions.md | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 ruby/rake-only-lists-tasks-with-descriptions.md diff --git a/README.md b/README.md index 959ae11..e390ddb 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Passing Arguments To A Rake Task](ruby/passing-arguments-to-a-rake-task.md) - [Percent Notation](ruby/percent-notation.md) - [Question Mark Operator](ruby/question-mark-operator.md) +- [Rake Only Lists Tasks With Descriptions](ruby/rake-only-lists-tasks-with-descriptions.md) - [Squeeze Out The Extra Space](ruby/squeeze-out-the-extra-space.md) - [Summing Collections](ruby/summing-collections.md) - [`undef_method` And The Inheritance Hierarchy](ruby/undef-method-and-the-inheritance-hierarchy.md) diff --git a/ruby/rake-only-lists-tasks-with-descriptions.md b/ruby/rake-only-lists-tasks-with-descriptions.md new file mode 100644 index 0000000..ed7e835 --- /dev/null +++ b/ruby/rake-only-lists-tasks-with-descriptions.md @@ -0,0 +1,35 @@ +# Rake Only Lists Tasks With Descriptions + +Rake describes the `-T` flag as + +> Display the tasks (matching optional PATTERN) with descriptions, then exit. + +And `rake -T` does just exactly that. It lists all the tasks with +descriptions. Any rake task that you define without a `desc` will not be +included. + +Consider the following rake task definitions + +```ruby +desc 'foobar does this and that' +task :foobar do + puts 'this and that' +end + +task :foobaz do + puts 'not so much' +end +``` + +This is what I get when listing the rake tasks filtered by _foo_ + +```bash +$ rake -T foo +rake foobar # foobar does this and that +``` + +The `foobar` task (which has a description) is listed, but `foobaz` is not. + +A hack of sorts to get around this is to use the `-P` flag which will end up +listing all tasks even if they do not have a description (`rake -P | grep +'foo'`).