-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #845 as discussed. Comparing the two approaches of getting `argv`: 1. The "old" way, through `CLI::argv()`: ✔️ Works automatically and almost everywhere ❌ Small abstraction overhead on macOS ❌ Does not work in weird edge-cases such as missing `/proc` 2. This PR, through `app.ensure_utf8`: ✔️ True zero-overhead abstraction: you don't pay for what you don't use ✔️ Less moving parts than the "old" approach, probably can't be broken ❌ Requires extra code to be written by the user (which is sad because ideally everyone should use this by default) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
826415f
commit 0d4e191
Showing
10 changed files
with
218 additions
and
56 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
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
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
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
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
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
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
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,35 @@ | ||
// Copyright (c) 2017-2023, University of Cincinnati, developed by Henry Schreiner | ||
// under NSF AWARD 1414736 and by the respective contributors. | ||
// All rights reserved. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <CLI/CLI.hpp> | ||
#include <cstring> | ||
#include <iostream> | ||
|
||
int main(int argc, char **argv) { | ||
CLI::App app{"App description"}; | ||
char **original_argv = argv; | ||
argv = app.ensure_utf8(argv); | ||
|
||
#ifdef _WIN32 | ||
for(int i = 0; i < argc; i++) { | ||
if(std::strcmp(argv[i], original_argv[i]) != 0) { | ||
std::cerr << argv[i] << "\n"; | ||
std::cerr << original_argv[i] << "\n"; | ||
return i + 1; | ||
} | ||
argv[i][0] = 'x'; // access it to check that it is accessible | ||
} | ||
|
||
#else | ||
(void)argc; | ||
|
||
if(original_argv != argv) { | ||
return -1; | ||
} | ||
#endif | ||
|
||
return 0; | ||
} |
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,36 @@ | ||
// Copyright (c) 2017-2023, University of Cincinnati, developed by Henry Schreiner | ||
// under NSF AWARD 1414736 and by the respective contributors. | ||
// All rights reserved. | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <CLI/CLI.hpp> | ||
#include <cstring> | ||
#include <iostream> | ||
|
||
int main(int argc, char **argv) { | ||
CLI::App app{"App description"}; | ||
char **original_argv = argv; | ||
argv = app.ensure_utf8(argv); | ||
argv = app.ensure_utf8(argv); // completely useless but works ok | ||
|
||
#ifdef _WIN32 | ||
for(int i = 0; i < argc; i++) { | ||
if(std::strcmp(argv[i], original_argv[i]) != 0) { | ||
std::cerr << argv[i] << "\n"; | ||
std::cerr << original_argv[i] << "\n"; | ||
return i + 1; | ||
} | ||
argv[i][0] = 'x'; // access it to check that it is accessible | ||
} | ||
|
||
#else | ||
(void)argc; | ||
|
||
if(original_argv != argv) { | ||
return -1; | ||
} | ||
#endif | ||
|
||
return 0; | ||
} |
Oops, something went wrong.