Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -C/--directory option the same as GNU make #376

Merged
merged 1 commit into from Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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