Skip to content
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

1299 Add CLI option for converting files to TOML #1741

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 19 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,34 @@ int main(int args, char **argv)
}

// Save input file to new output filename and quit?
if (options.writeInputFilename())
if (options.writeInputFilename() || options.toTomlFile())
{
Messenger::print("Saving input file to '{}'...\n", options.writeInputFilename().value());
std::string filename = options.writeInputFilename().value_or(options.toTomlFile().value());
Messenger::print("Saving input file to '{}'...\n", filename);
bool result;
if (dissolve.worldPool().isMaster())
{
result = dissolve.saveInput(options.writeInputFilename().value());
if (result)
dissolve.worldPool().decideTrue();
if (options.writeInputFilename())
{
result = dissolve.saveInput(options.writeInputFilename().value());
if (result)
dissolve.worldPool().decideTrue();
else
dissolve.worldPool().decideFalse();
}
else
dissolve.worldPool().decideFalse();
{
auto toml = dissolve.serialise();
std::ofstream outfile(options.toTomlFile().value());
outfile << toml;
outfile.close();
result = 1;
rprospero marked this conversation as resolved.
Show resolved Hide resolved
}
}
else
result = dissolve.worldPool().decision();
if (!result)
Messenger::error("Failed to save input file to '{}'.\n", options.writeInputFilename().value());
Messenger::error("Failed to save input file to '{}'.\n", filename);

// Reload the written file and continue?
if (options.writeInputAndReload())
Expand Down
4 changes: 4 additions & 0 deletions src/main/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ int CLIOptions::parse(const int args, char **argv, bool isGUI, bool isParallel)
app.add_option("-w,--write-input", writeInputFilename_,
"Write out the current simulation input to the file specified and then quit")
->group("Input Files");
app.add_option("--to-toml", toTomlFile_, "Convert input file into TOML format")->group("Output Files");
app.add_flag("--reload-after-write", writeInputAndReload_,
"Reload the input generated by --write-input and continue instead of quitting")
->group("Input Files");
Expand Down Expand Up @@ -108,3 +109,6 @@ bool CLIOptions::ignoreRestartFile() const { return ignoreRestartFile_; }

// Return whether to prevent writing of the restart file
bool CLIOptions::noRestartFile() const { return noRestartFile_; };

// Return output destination for TOML conversion
std::optional<std::string> CLIOptions::toTomlFile() const { return toTomlFile_; }
4 changes: 4 additions & 0 deletions src/main/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class CLIOptions
bool ignoreRestartFile_{false};
// Whether to prevent writing of the restart file
bool noRestartFile_{false};
// File for TOML conversion
std::optional<std::string> toTomlFile_;

public:
// Parse Result enum
Expand Down Expand Up @@ -66,4 +68,6 @@ class CLIOptions
bool ignoreRestartFile() const;
// Return whether to prevent writing of the restart file
bool noRestartFile() const;
// Return output destination for TOML conversion
std::optional<std::string> toTomlFile() const;
};
Loading