-
Notifications
You must be signed in to change notification settings - Fork 109
Add response file support for command line options #121
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
23bb86b
Add response file support for command line options
timr1126 80ba0e7
Cleanup code
timr1126 b8acf63
Add tests for response files
timr1126 c16ac11
More cleanup
timr1126 49ec12f
Merge branch 'master' into t-tiroma-response-files
timr1126 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,154 @@ | ||
| #include "pch.h" | ||
| #include "winrt/Windows.Foundation.h" | ||
| #include "cmd_reader.h" | ||
| #include <fstream> | ||
|
|
||
| using namespace xlang::cmd; | ||
|
|
||
| class response_file | ||
| { | ||
| const char* resp_file_name = "respfile.txt"; | ||
| void write_response_file(const char* input) | ||
| { | ||
| std::ofstream resp_file(resp_file_name); | ||
| if (!resp_file.is_open()) | ||
| FAIL("Response file could not be created"); | ||
| resp_file << input; | ||
| resp_file.close(); | ||
| } | ||
|
|
||
| void remove_response_file() | ||
| { | ||
| std::remove(resp_file_name); | ||
| } | ||
|
|
||
| public: | ||
| response_file(const char* input) | ||
| { | ||
| write_response_file(input); | ||
| } | ||
|
|
||
| reader create_reader(size_t const argc, const char* argv[], std::vector<option> const& options) | ||
| { | ||
| return reader{ argc, argv, options }; | ||
| } | ||
|
|
||
| ~response_file() | ||
| { | ||
| remove_response_file(); | ||
| } | ||
| }; | ||
|
|
||
| TEST_CASE("CmdReader") | ||
|
devhawk marked this conversation as resolved.
|
||
| { | ||
| static const std::vector<option> options | ||
| { | ||
| { "input", 1 }, | ||
| { "reference", 0 }, | ||
| { "output", 0, 1 }, | ||
| { "component", 0, 1 }, | ||
| { "filter", 0 }, | ||
| { "name", 0, 1 }, | ||
| { "verbose", 0, 0 }, | ||
| }; | ||
|
|
||
| // input and output | ||
| { | ||
| const char* argv[] = { "progname", "-in", "example_file.in", "-out", "example_file.out" }; | ||
| const size_t argc = 5; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all argc values can be = _countof(argv) |
||
| reader args{ argc, argv, options }; | ||
|
|
||
| REQUIRE(args.exists("input")); | ||
| REQUIRE(args.value("input") == "example_file.in"); | ||
| REQUIRE_FALSE(args.exists("reference")); | ||
| REQUIRE(args.exists("output")); | ||
| REQUIRE(args.value("output") == "example_file.out"); | ||
| REQUIRE_FALSE(args.exists("filter")); | ||
| REQUIRE_FALSE(args.exists("name")); | ||
| REQUIRE_FALSE(args.exists("verbose")); | ||
| } | ||
|
|
||
| // response file #1: filename no quotes | ||
| { | ||
| const char* argv[] = { "progname", "@respfile.txt" }; | ||
| const size_t argc = _countof(argv); | ||
|
|
||
| response_file rf{ R"(-in example_file.in -out example_file.out)" }; | ||
| reader args = rf.create_reader(argc, argv, options); | ||
|
|
||
| REQUIRE(args.exists("input")); | ||
| REQUIRE(args.value("input") == "example_file.in"); | ||
| REQUIRE_FALSE(args.exists("reference")); | ||
| REQUIRE(args.exists("output")); | ||
| REQUIRE(args.value("output") == "example_file.out"); | ||
| REQUIRE_FALSE(args.exists("filter")); | ||
| REQUIRE_FALSE(args.exists("name")); | ||
| REQUIRE_FALSE(args.exists("verbose")); | ||
| } | ||
|
|
||
| // response file #2: filename with quotes | ||
| { | ||
| const char* argv[] = { "progname", "@respfile.txt" }; | ||
| const size_t argc = _countof(argv); | ||
|
|
||
| response_file rf{ R"(-in "example file.in" -out "example file.out")" }; | ||
| reader args = rf.create_reader(argc, argv, options); | ||
|
|
||
| REQUIRE(args.exists("input")); | ||
| REQUIRE(args.value("input") == "example file.in"); | ||
| REQUIRE_FALSE(args.exists("reference")); | ||
| REQUIRE(args.exists("output")); | ||
| REQUIRE(args.value("output") == "example file.out"); | ||
| REQUIRE_FALSE(args.exists("filter")); | ||
| REQUIRE_FALSE(args.exists("name")); | ||
| REQUIRE_FALSE(args.exists("verbose")); | ||
| } | ||
|
|
||
| // response file #3: filename with quote within name | ||
| { | ||
| const char* argv[] = { "progname", "@respfile.txt" }; | ||
| const size_t argc = _countof(argv); | ||
|
|
||
| response_file rf{ R"(-in example\"file.in -out example\"file.out)" }; | ||
| reader args = rf.create_reader(argc, argv, options); | ||
|
|
||
| REQUIRE(args.exists("input")); | ||
| REQUIRE(args.value("input") == R"(example"file.in)"); | ||
| REQUIRE_FALSE(args.exists("reference")); | ||
| REQUIRE(args.exists("output")); | ||
| REQUIRE(args.value("output") == R"(example"file.out)"); | ||
| REQUIRE_FALSE(args.exists("filter")); | ||
| REQUIRE_FALSE(args.exists("name")); | ||
| REQUIRE_FALSE(args.exists("verbose")); | ||
| } | ||
|
|
||
| // response file #4: really really long path | ||
| { | ||
| const char* argv[] = { "progname", "@respfile.txt" }; | ||
| const size_t argc = _countof(argv); | ||
| std::string file_name_in(R"(C:\)"); | ||
| std::string file_name_out(R"(C:\)"); | ||
| std::string input_str("-in "); | ||
|
|
||
| for (int i = 0; i < 500; i++) { | ||
| file_name_in.append(R"(dirname\)"); | ||
| file_name_out.append(R"(dirname\)"); | ||
| } | ||
|
|
||
| file_name_in.append("example_file.in"); | ||
| file_name_out.append("example_file.out"); | ||
| input_str.append(file_name_in).append(" -out ").append(file_name_out); | ||
|
|
||
| response_file rf{ input_str.data() }; | ||
| reader args = rf.create_reader(argc, argv, options); | ||
|
|
||
| REQUIRE(args.exists("input")); | ||
| REQUIRE(args.value("input") == file_name_in); | ||
| REQUIRE_FALSE(args.exists("reference")); | ||
| REQUIRE(args.exists("output")); | ||
| REQUIRE(args.value("output") == file_name_out); | ||
| REQUIRE_FALSE(args.exists("filter")); | ||
| REQUIRE_FALSE(args.exists("name")); | ||
| REQUIRE_FALSE(args.exists("verbose")); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comment that this line is intended to help diagnose misuse of the '@' prefix (e.g., when supplying metadata files)