Skip to content

Commit

Permalink
Refactor the show_tasks option code into function and replace
Browse files Browse the repository at this point in the history
There was very similar code in 3 places in this function, so I broke it
out into it's own function.

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information
Sam Phippen committed Oct 14, 2012
1 parent 50218b0 commit e42c52e
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions lib/rake/application.rb
Expand Up @@ -30,6 +30,12 @@ class Application

DEFAULT_RAKEFILES = ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb'].freeze

def self.set_tasks_options(show_tasks, value, options)
options.show_tasks = show_tasks
options.show_task_pattern = Regexp.new(value || '')
Rake::TaskManager.record_task_metadata = true
end

# Initialize a Rake::Application object.
def initialize
super
Expand Down Expand Up @@ -284,6 +290,7 @@ def display_prerequisites
end
end


# A list of all the standard options used in rake, suitable for
# passing to OptionParser.
def standard_rake_options
Expand All @@ -296,9 +303,17 @@ def standard_rake_options
],
['--describe', '-D [PATTERN]', "Describe the tasks (matching optional PATTERN), then exit.",
lambda { |value|
options.show_tasks = :describe
options.show_task_pattern = Regexp.new(value || '')
TaskManager.record_task_metadata = true
Rake::Application.set_tasks_options :describe, value, options
}
],
['--tasks', '-T [PATTERN]', "Display the tasks (matching optional PATTERN) with descriptions, then exit.",
lambda { |value|
Rake::Application.set_tasks_options :tasks, value, options
}
],
['--where', '-W [PATTERN]', "Describe the tasks (matching optional PATTERN), then exit.",
lambda { |value|
Rake::Application.set_tasks_options :lines, value, options
}
],
['--dry-run', '-n', "Do a dry run without executing actions.",
Expand Down Expand Up @@ -384,13 +399,6 @@ def standard_rake_options
"Use standard project Rakefile search paths, ignore system wide rakefiles.",
lambda { |value| options.ignore_system = true }
],
['--tasks', '-T [PATTERN]', "Display the tasks (matching optional PATTERN) with descriptions, then exit.",
lambda { |value|
options.show_tasks = :tasks
options.show_task_pattern = Regexp.new(value || '')
Rake::TaskManager.record_task_metadata = true
}
],
['--trace', '-t', "Turn on invoke/execute tracing, enable full backtrace.",
lambda { |value|
options.trace = true
Expand All @@ -406,13 +414,6 @@ def standard_rake_options
exit
}
],
['--where', '-W [PATTERN]', "Describe the tasks (matching optional PATTERN), then exit.",
lambda { |value|
options.show_tasks = :lines
options.show_task_pattern = Regexp.new(value || '')
Rake::TaskManager.record_task_metadata = true
}
],
['--no-deprecation-warnings', '-X', "Disable the deprecation warnings.",
lambda { |value|
options.ignore_deprecate = true
Expand Down

0 comments on commit e42c52e

Please sign in to comment.