Skip to content

Commit

Permalink
Improve arg parse
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Dec 16, 2023
1 parent fa04269 commit feb04f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ jobs:
- name: Test the second generation
run: ./poac-out/debug/poac test --verbose

- name: Third Generation Build
run: ./poac-out/debug/poac build --verbose --release

- name: Test the third generation
run: ./poac-out/release/poac test --verbose --release
- name: Third Generation Build & Test
run: ./poac-out/debug/poac --verbose run --release test --verbose --release

# - name: Test Poac
# run: ctest --output-on-failure --verbose
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ jobs:
- name: Test the second generation
run: ./poac-out/debug/poac test --verbose

- name: Third Generation Build
run: ./poac-out/debug/poac build --verbose --release

- name: Test the third generation
run: ./poac-out/release/poac test --verbose --release
- name: Third Generation Build & Test
run: ./poac-out/debug/poac --verbose run --release test --verbose --release

# - name: Test Poac
# run: ctest --output-on-failure --verbose
Expand Down
20 changes: 16 additions & 4 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,28 @@ int help(Vec<String> args) {
int main(int argc, char* argv[]) {
// Parse global options
Vec<String> args;
bool isVerbositySet = false;
for (int i = 1; i < argc; ++i) {
String arg = argv[i];
if (arg == "-v" || arg == "--version") {
std::cout << "poac " << POAC_VERSION << '\n';
return EXIT_SUCCESS;
}
if (arg == "--verbose") {
Logger::setLevel(LogLevel::debug);
} else if (arg == "-q" || arg == "--quiet") {
Logger::setLevel(LogLevel::error);

// This is a bit of a hack to allow the global options to be specified
// in poac run, e.g., `poac run --verbose test --verbose`. This will
// remove the first --verbose and execute the run command as verbose,
// then run the test command as verbose.
if (!isVerbositySet) {
if (arg == "--verbose") {
Logger::setLevel(LogLevel::debug);
isVerbositySet = true;
} else if (arg == "-q" || arg == "--quiet") {
Logger::setLevel(LogLevel::error);
isVerbositySet = true;
} else {
args.push_back(arg);
}
} else {
args.push_back(arg);
}
Expand Down

0 comments on commit feb04f1

Please sign in to comment.