Skip to content

Commit c591402

Browse files
authored
Merge pull request #376 from nobu/directory-option
Add -C/--directory option the same as GNU make
2 parents 0ce7938 + abfa788 commit c591402

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/rake/application.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ def standard_rake_options # :nodoc:
433433
select_tasks_to_show(options, :describe, value)
434434
}
435435
],
436+
["--directory", "-C [DIRECTORY]",
437+
"Change to DIRECTORY before doing anything.",
438+
lambda { |value|
439+
Dir.chdir value
440+
@original_dir = Dir.pwd
441+
}
442+
],
436443
["--dry-run", "-n",
437444
"Do a dry run without executing actions.",
438445
lambda { |value|

test/test_rake_application_options.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ def test_describe_with_pattern
6565
end
6666
end
6767

68+
def test_directory
69+
pwd = Dir.pwd
70+
[["--directory"], "--directory=", ["-C"], "-C"].each do |flag|
71+
Dir.mktmpdir do |dir|
72+
begin
73+
flags(flag.dup << dir) do
74+
assert_equal(File.realpath(dir), @app.original_dir)
75+
end
76+
ensure
77+
Dir.chdir(pwd)
78+
end
79+
begin
80+
assert_raises(Errno::ENOENT) do
81+
flags(flag.dup << dir+"/nonexistent")
82+
end
83+
ensure
84+
Dir.chdir(pwd)
85+
end
86+
end
87+
end
88+
end
89+
6890
def test_execute
6991
$xyzzy = 0
7092
flags("--execute=$xyzzy=1", "-e $xyzzy=1") do

0 commit comments

Comments
 (0)