Commit 20f9200d authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

changed semantics of the output directory/file/path

parent f30759ed
Loading
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -504,7 +504,7 @@ int main(int argc, char * argv[])
{
	Parameters args;
	std::filesystem::path input_file;
	std::filesystem::path output_dir = ".";
	std::filesystem::path output_path = ".";
	bool show_help = false;

	auto cli = lyra::cli();
@@ -513,8 +513,13 @@ int main(int argc, char * argv[])
	args.set_cli_options(cli);

	// positional arguments (should be generally defined after optional arguments)
	cli |= lyra::arg(input_file, "input_file")("Input file (supported formats: OFF, STL, OBJ, PLY, VTP, GOCAD).").required();
	cli |= lyra::arg(output_dir, "output_dir")("Output directory." + fmt_default(output_dir));
	cli |= lyra::arg(input_file, "input_file")
			("Input file (supported formats: OFF, STL, OBJ, PLY, VTP, GOCAD).").required();
	cli |= lyra::arg(output_path, "output_path")
			("Output path. If it is an existing directory, the stem of "
			 "input_file (i.e., base file name without suffix) is appended to "
			 "output_path. Otherwise, output_path denotes the output file and "
			 "it must end with the \".vtu\" suffix." + fmt_default(output_path));

	auto result = cli.parse({ argc, argv });

@@ -537,20 +542,21 @@ int main(int argc, char * argv[])
		return EXIT_FAILURE;
	}

	// check if the output directory exists
	if (!std::filesystem::is_directory(output_dir)) {
		std::cerr << "Error: output_dir \"" + output_dir.string() + "\" is not an existing directory." << std::endl;
	// check if output_path is an existing directory
	if (std::filesystem::is_directory(output_path))
		output_path /= (input_file.stem().string() + ".vtu");
	// ensure that output_path ends with ".vtu"
	else if (output_path.extension() != ".vtu") {
		std::cerr << "Error: output_path \"" + output_path.string() + "\" does not end with \".vtu\"." << std::endl;
		return EXIT_FAILURE;
	}
	std::filesystem::path output_file = output_dir / (input_file.stem().string() + ".vtu");

	std::cout << "Input file: " << input_file << "\n";
	std::cout << "Output directory: " << output_dir << "\n";
	std::cout << "Output VTU file: " << output_file << "\n";
	std::cout << "Output file: " << output_path << "\n";
	args.print_options(std::cout);

	try {
		polyDomain(input_file, output_file, args);
		polyDomain(input_file, output_path, args);
	}
	catch (std::logic_error & e) {
		std::cerr << "Logic error: " << e.what() << std::endl;