Skip to content

Commit

Permalink
Merge pull request #376 from nobu/directory-option
Browse files Browse the repository at this point in the history
Add -C/--directory option the same as GNU make
  • Loading branch information
hsbt committed Apr 23, 2021
2 parents 0ce7938 + abfa788 commit c591402
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
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
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 c591402

Please sign in to comment.