Skip to content

Commit

Permalink
Fix extract_filename function (#409)
Browse files Browse the repository at this point in the history
Fix extract_filename function
  • Loading branch information
anutosh491 authored Dec 17, 2024
1 parent c216de1 commit b43c88c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ jobs:
- name: Get number of CPU cores
uses: SimenB/github-actions-cpu-cores@v2

- name: Install mamba
uses: mamba-org/setup-micromamba@v1
- name: Install micromamba
uses: mamba-org/setup-micromamba@v2
with:
environment-file: environment-wasm-build.yml
environment-name: xeus-wasm-build
Expand Down
11 changes: 10 additions & 1 deletion include/xeus/xhelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ namespace xeus
{
XEUS_API std::string get_start_message(const xconfiguration& config);

XEUS_API std::string extract_filename(int argc, char* argv[]);
/**
* @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[]);

Expand Down
2 changes: 1 addition & 1 deletion src/xhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion test/test_unit_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b43c88c

Please sign in to comment.