Skip to content

feat: Add command -cwd (change working directory) #1024

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 4 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ auto main(
return EXIT_FAILURE;
}

if (std::filesystem::exists(flag_cwd)) {
std::filesystem::current_path(flag_cwd);
}

// For each Cpp2 source file
int exit_status = EXIT_SUCCESS;
for (auto const& arg : cmdline.arguments())
Expand Down
17 changes: 16 additions & 1 deletion source/to_cpp1.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ static cmdline_processor::register_flag cmd_cpp1_filename(
[](std::string const& name) { flag_cpp1_filename = name; }
);

static auto flag_cwd = std::filesystem::path{};
static cpp2::cmdline_processor::register_flag cmd_cwd(
9,
"cwd path",
"Change current working directory to path",
nullptr,
[](std::string const& path) { flag_cwd = { path }; }
);

static auto flag_no_exceptions = false;
static cmdline_processor::register_flag cmd_no_exceptions(
4,
Expand Down Expand Up @@ -1245,8 +1254,14 @@ class cppfront

// Now we'll open the Cpp1 file
auto cpp1_filename = sourcefile.substr(0, std::ssize(sourcefile) - 1);

// Use explicit filename override if present,
// otherwise strip leading path
if (!flag_cpp1_filename.empty()) {
cpp1_filename = flag_cpp1_filename; // use override if present
cpp1_filename = flag_cpp1_filename;
}
else {
cpp1_filename = std::filesystem::path(cpp1_filename).filename().string();
}

printer.open(
Expand Down
Loading