-
Notifications
You must be signed in to change notification settings - Fork 1
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
Sanitise input data #200
Merged
Merged
Sanitise input data #200
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
bed9892
Remove create_output_folder() function
alexdewar 50505e1
Use std::filesystem::path cf. std::string in a few places
alexdewar 2700324
Drop support for v1 config files
alexdewar 358c762
load_configuration(): Remove some indentation
alexdewar a2fd569
Make separate function for rebasing paths
alexdewar c66c0b8
Put new functions for loading JSON into configuration.cpp
alexdewar d9a8ab8
Add ConfigurationError class and use in a few places
alexdewar 100ffd7
Remove unused field
alexdewar d1cc571
Clean up and add extra error checking to config file loading
alexdewar f480522
Remove superfluous helper functions
alexdewar 2597d32
Fix: Seemingly MSVC isn't happy about casting filesystem::paths to st…
alexdewar 9a1188c
Move some functions out of configuration.cpp to program.cpp
alexdewar 3efc2be
Put functionality related to command-line args in own cpp file
alexdewar 0d1f803
Move some parsing functions into configuration_parsing.cpp
alexdewar 3d72290
Put configuration parsing helper function defs into own header
alexdewar edc505d
Rename some functions and mark noexcept
alexdewar 04eab1e
Remove unused API version functionality
alexdewar a7ee4b5
Move version.h.in to src/HealthGPS
alexdewar 7ff7cc1
Build most console functionality as lib for testability
alexdewar c6306a1
Spelling
alexdewar 3934a7f
Add JSON (de)serialisation code for Interval<> class
alexdewar 3111772
Make SettingsInfo.age_range an IntegerInterval
alexdewar 35b93a2
Base OptionalRange on Interval class and rename
alexdewar 9557033
Add tests for some config code
alexdewar efd97bf
Merge remote-tracking branch 'origin/main' into sanitise_input_data
alexdewar 9f5eaec
Fix typo
alexdewar 6180f36
Allow for parsing JSON objects to any map type with Identifier as key
alexdewar babf513
Use default comparators cf. custom operator==
alexdewar f5f55f4
Add test for load_interventions
alexdewar 3191348
Make active intervention into an optional type
alexdewar 4c9ee02
Add final tests for config code
alexdewar 5625e26
MSVC resources file should live in HealthGPS.Console/
alexdewar d4f531e
Remove unused var
alexdewar d5c2aa7
Use different get_to overload in a couple of places
alexdewar d19cdd8
Explicitly convert to string to appease MSVC
alexdewar c1b6636
Fix: Appease g++ v11 by not using structured bindings
alexdewar 9d9801d
Fix narrowing warning on MSVC
alexdewar 7deec87
Fix: Interval class's members should be default-initialised
alexdewar aafadfb
Fix/suppress bugprone-exception-escape clang-tidy warning
alexdewar 6f19143
Fix: Use absolute cf. weakly canonical paths in rebase_valid_path()
alexdewar cbd23d7
Fix docstring warnings and rename a couple of args
alexdewar a592a1b
Add docstrings to poco.h
alexdewar 26f1b31
Remove unused function definition
alexdewar 6438589
Add file-level documentation for several headers
alexdewar 0157f76
range parameter doesn't need a default value
alexdewar c9e3b2d
Revert "range parameter doesn't need a default value"
jamesturner246 72d6519
Remove special-casing for std::optional<Interval<T>>
alexdewar 00fc19f
Merge branch 'main' into sanitise_input_data
alexdewar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "command_options.h" | ||
#include "version.h" | ||
|
||
#include <fmt/color.h> | ||
|
||
#include <iostream> | ||
|
||
namespace host { | ||
|
||
cxxopts::Options create_options() { | ||
cxxopts::Options options("HealthGPS.Console", "Health-GPS microsimulation for policy options."); | ||
options.add_options()("f,file", "Configuration file full name.", cxxopts::value<std::string>())( | ||
"s,storage", "Path to root folder of the data storage.", cxxopts::value<std::string>())( | ||
"j,jobid", "The batch execution job identifier.", | ||
cxxopts::value<int>())("verbose", "Print more information about progress", | ||
cxxopts::value<bool>()->default_value("false"))( | ||
"help", "Help about this application.")("version", "Print the application version number."); | ||
|
||
return options; | ||
} | ||
|
||
CommandOptions parse_arguments(cxxopts::Options &options, int &argc, char *argv[]) { | ||
namespace fs = std::filesystem; | ||
|
||
CommandOptions cmd; | ||
try { | ||
cmd.success = true; | ||
cmd.exit_code = EXIT_SUCCESS; | ||
cmd.verbose = false; | ||
auto result = options.parse(argc, argv); | ||
if (result.count("help")) { | ||
std::cout << options.help() << std::endl; | ||
cmd.success = false; | ||
return cmd; | ||
} | ||
|
||
if (result.count("version")) { | ||
fmt::print("Version {}\n\n", PROJECT_VERSION); | ||
cmd.success = false; | ||
return cmd; | ||
} | ||
|
||
cmd.verbose = result["verbose"].as<bool>(); | ||
if (cmd.verbose) { | ||
fmt::print(fg(fmt::color::dark_salmon), "Verbose output enabled\n"); | ||
} | ||
|
||
if (result.count("file")) { | ||
cmd.config_file = result["file"].as<std::string>(); | ||
if (cmd.config_file.is_relative()) { | ||
cmd.config_file = std::filesystem::absolute(cmd.config_file); | ||
fmt::print("Configuration file..: {}\n", cmd.config_file.string()); | ||
} | ||
} | ||
|
||
if (!fs::exists(cmd.config_file)) { | ||
fmt::print(fg(fmt::color::red), "\nConfiguration file: {} not found.\n", | ||
cmd.config_file.string()); | ||
cmd.exit_code = EXIT_FAILURE; | ||
} | ||
|
||
if (result.count("storage")) { | ||
cmd.storage_folder = result["storage"].as<std::string>(); | ||
if (cmd.storage_folder.is_relative()) { | ||
cmd.storage_folder = std::filesystem::absolute(cmd.storage_folder); | ||
fmt::print("File storage folder.: {}\n", cmd.storage_folder.string()); | ||
} | ||
} | ||
|
||
if (!fs::exists(cmd.storage_folder)) { | ||
fmt::print(fg(fmt::color::red), "\nFile storage folder: {} not found.\n", | ||
cmd.storage_folder.string()); | ||
cmd.exit_code = EXIT_FAILURE; | ||
} | ||
|
||
if (result.count("jobid")) { | ||
cmd.job_id = result["jobid"].as<int>(); | ||
if (cmd.job_id < 1) { | ||
fmt::print(fg(fmt::color::red), | ||
"\nJob identifier value outside range: (0 < x) given: {}.\n", | ||
std::to_string(cmd.job_id)); | ||
cmd.exit_code = EXIT_FAILURE; | ||
} | ||
} | ||
|
||
cmd.success = cmd.exit_code == EXIT_SUCCESS; | ||
} catch (const cxxopts::exceptions::exception &ex) { | ||
fmt::print(fg(fmt::color::red), "\nInvalid command line argument: {}.\n", ex.what()); | ||
fmt::print("\n{}\n", options.help()); | ||
cmd.success = false; | ||
cmd.exit_code = EXIT_FAILURE; | ||
} | ||
|
||
return cmd; | ||
} | ||
} // namespace host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @file | ||
* @brief Functionality for parsing console application's command-line arguments | ||
*/ | ||
#pragma once | ||
#include <cxxopts.hpp> | ||
|
||
#include <filesystem> | ||
|
||
namespace host { | ||
/// @brief Defines the Command Line Interface (CLI) arguments options | ||
struct CommandOptions { | ||
/// @brief Indicates whether the argument parsing succeed | ||
bool success{}; | ||
|
||
/// @brief The exit code to return, in case of CLI arguments parsing failure | ||
int exit_code{}; | ||
|
||
/// @brief The configuration file argument value | ||
std::filesystem::path config_file{}; | ||
|
||
/// @brief The back-end storage full path argument value | ||
std::filesystem::path storage_folder{}; | ||
|
||
/// @brief Indicates whether the application logging is verbose | ||
bool verbose{}; | ||
|
||
/// @brief The batch job identifier value, optional. | ||
int job_id{}; | ||
}; | ||
|
||
/// @brief Creates the command-line interface (CLI) options | ||
/// @return Health-GPS CLI options | ||
cxxopts::Options create_options(); | ||
|
||
/// @brief Parses the command-line interface (CLI) arguments | ||
/// @param options The valid CLI options | ||
/// @param argc Number of input arguments | ||
/// @param argv List of input arguments | ||
/// @return User command-line options | ||
CommandOptions parse_arguments(cxxopts::Options &options, int &argc, char *argv[]); | ||
|
||
} // namespace host |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why no
target_compile_features(HealthGPS.Console PUBLIC cxx_std_${CMAKE_CXX_STANDARD})
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's redundant because targets are already built using
${CMAKE_CXX_STANDARD}
anyway.