Skip to content

Commit

Permalink
Add -C/--directory option the same as GNU make
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Feb 17, 2021
1 parent c2eeae2 commit abfa788
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/rake/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ def standard_rake_options # :nodoc:
select_tasks_to_show(options, :describe, value)
}
],
["--directory", "-C [DIRECTORY]",
"Change to DIRECTORY before doing anything.",
lambda { |value|
Dir.chdir value
@original_dir = Dir.pwd
}
],
["--dry-run", "-n",
"Do a dry run without executing actions.",
lambda { |value|
Expand Down
22 changes: 22 additions & 0 deletions test/test_rake_application_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ def test_describe_with_pattern
end
end

def test_directory
pwd = Dir.pwd
[["--directory"], "--directory=", ["-C"], "-C"].each do |flag|
Dir.mktmpdir do |dir|
begin
flags(flag.dup << dir) do
assert_equal(File.realpath(dir), @app.original_dir)
end
ensure
Dir.chdir(pwd)
end
begin
assert_raises(Errno::ENOENT) do
flags(flag.dup << dir+"/nonexistent")
end
ensure
Dir.chdir(pwd)
end
end
end
end

def test_execute
$xyzzy = 0
flags("--execute=$xyzzy=1", "-e $xyzzy=1") do
Expand Down

0 comments on commit abfa788

Please sign in to comment.