-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forward unmodified ARGV to subcommand (#631)
* Pass all ARGV arguments verbatim to subcommand Avoid altering original `ARGV` when combining it with possible `SHARDS_OPTS` variable and pass them verbatim to the subcommand. Introduce a naive integration test for subcommand to validate the change works correctly. * Fixes passing --help to subcommand Avoid OptionParser to short-circuit `--help` and return immediately by setting a flag for it and evaluating at the end of the processing of unknown options. This is only done for the CLI invocation and is not part of Shards module (as the help and usage options are only available in this context). * Only use dummy executable on Windows Follow the pattern used in other tests and use simple `sh` script on non-Windows platforms. * Avoid usage of class properties to handle help behavior Revert the usage of class property introduced in 5a6dc6c and leverage instead on a pure instance variable in the context of `Shards.run`.
- Loading branch information
1 parent
655a3b0
commit 48b7295
Showing
2 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "./spec_helper" | ||
|
||
describe "subcommand" do | ||
it "forwards all arguments to subcommand" do | ||
create_shard("dummy", "0.1.0") | ||
{% if flag?(:win32) %} | ||
create_executable "dummy", "bin/shards-dummy", %(print ARGV.join(" ")) | ||
{% else %} | ||
path = create_file("dummy", "bin/shards-dummy", "#!/bin/sh\necho $@\n") | ||
File.chmod(path, 0o755) | ||
{% end %} | ||
|
||
with_path(git_path("dummy/bin")) do | ||
output = run("shards dummy --no-color --verbose --unknown other argument") | ||
output.should contain(%(--no-color --verbose --unknown other argument)) | ||
end | ||
end | ||
|
||
it "correctly forwards '--help' option to subcommand" do | ||
create_shard("dummy", "0.1.0") | ||
{% if flag?(:win32) %} | ||
create_executable "dummy", "bin/shards-dummy", %(print ARGV.join(" ")) | ||
{% else %} | ||
path = create_file("dummy", "bin/shards-dummy", "#!/bin/sh\necho $@\n") | ||
File.chmod(path, 0o755) | ||
{% end %} | ||
|
||
with_path(git_path("dummy/bin")) do | ||
output = run("shards dummy --help") | ||
output.should contain(%(--help)) | ||
end | ||
end | ||
end | ||
|
||
private def with_path(path) | ||
old_path = ENV["PATH"] | ||
ENV["PATH"] = "#{File.expand_path(path)}#{Process::PATH_DELIMITER}#{ENV["PATH"]}" | ||
yield | ||
ensure | ||
ENV["PATH"] = old_path | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters