From 7af0b73b16a36cbb79a1aa87c671bc296382425e Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Sat, 28 Sep 2024 19:14:05 +0530 Subject: [PATCH 1/2] Fix extract_filename function --- .github/workflows/main.yml | 6 +++--- include/xeus/xhelper.hpp | 2 +- src/xhelper.cpp | 2 +- test/test_unit_kernel.cpp | 4 +++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e0e74091..45869b31 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,7 +38,7 @@ jobs: uses: SimenB/github-actions-cpu-cores@v2 - name: Install mamba - uses: mamba-org/setup-micromamba@v1 + uses: mamba-org/setup-micromamba@v2 with: environment-file: environment-dev.yml environment-name: xeus @@ -91,7 +91,7 @@ jobs: - uses: actions/checkout@v4 - name: Install mamba - uses: mamba-org/setup-micromamba@v1 + uses: mamba-org/setup-micromamba@v2 with: environment-file: environment-dev.yml environment-name: xeus @@ -144,7 +144,7 @@ jobs: uses: SimenB/github-actions-cpu-cores@v2 - name: Install mamba - uses: mamba-org/setup-micromamba@v1 + uses: mamba-org/setup-micromamba@v2 with: environment-file: environment-wasm-build.yml environment-name: xeus-wasm-build diff --git a/include/xeus/xhelper.hpp b/include/xeus/xhelper.hpp index 6ff3b692..c06354a6 100644 --- a/include/xeus/xhelper.hpp +++ b/include/xeus/xhelper.hpp @@ -24,7 +24,7 @@ namespace xeus { XEUS_API std::string get_start_message(const xconfiguration& config); - XEUS_API std::string extract_filename(int argc, char* argv[]); + XEUS_API std::string extract_filename(int &argc, char* argv[]); XEUS_API bool should_print_version(int argc, char* argv[]); diff --git a/src/xhelper.cpp b/src/xhelper.cpp index 98d999f3..783cc6a4 100644 --- a/src/xhelper.cpp +++ b/src/xhelper.cpp @@ -30,7 +30,7 @@ namespace xeus return kernel_info; } - std::string extract_filename(int argc, char* argv[]) + std::string extract_filename(int &argc, char* argv[]) { std::string res = ""; for (int i = 0; i < argc; ++i) diff --git a/test/test_unit_kernel.cpp b/test/test_unit_kernel.cpp index 97a967ee..1acb78c5 100644 --- a/test/test_unit_kernel.cpp +++ b/test/test_unit_kernel.cpp @@ -55,11 +55,13 @@ namespace xeus TEST_CASE("extract_filename") { + int argc = 3; char* argv[2]; argv[0] = (char*)"-f"; argv[1] = (char*)"connection.json"; - std::string file_name = extract_filename(3, argv); + std::string file_name = extract_filename(argc, argv); REQUIRE_EQ(file_name, "connection.json"); + REQUIRE_EQ(argc, 1); } TEST_CASE("should_print_version") From 0de46b497686d9b0487d08b09bc945c8f4dce30b Mon Sep 17 00:00:00 2001 From: anutosh491 Date: Fri, 18 Oct 2024 16:23:18 +0530 Subject: [PATCH 2/2] Added documentation for extract_filename --- include/xeus/xhelper.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/xeus/xhelper.hpp b/include/xeus/xhelper.hpp index c06354a6..af0379d9 100644 --- a/include/xeus/xhelper.hpp +++ b/include/xeus/xhelper.hpp @@ -24,6 +24,15 @@ namespace xeus { XEUS_API std::string get_start_message(const xconfiguration& config); + /** + * @brief Extracts the filename from the command-line arguments and adjusts argc/argv. + * + * Searches for the "-f" flag in the arguments, extracts the following filename, and + * removes both from the argument list. `argc` is updated to reflect the changes. + * @param argc Reference to the argument count, modified if "-f" is found. + * @param argv Argument list, potentially modified. + * @return The extracted filename, or an empty string if not found. + */ XEUS_API std::string extract_filename(int &argc, char* argv[]); XEUS_API bool should_print_version(int argc, char* argv[]);