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

feat: add simulation config #1

Open
wants to merge 7 commits into
base: bitcoin-dev-project-fresheyes-staging-main-166
Choose a base branch
from

Conversation

adamjonas
Copy link
Owner

## What this PR does - Adds a SimulationConfig struct that Loads config values from an optional INI file and overwrites these values if corresponding command line arguments are passed - The config file contains custom values for the simulation ini [simln.conf] data_dir = "." sim_file = "sim.json" total_time= print_batch_size = 500 log_level = "info" expected_pmt_amt = 3800000 capacity_multiplier = 2 no_results = false log_interval = 60 - Makes configurable the log_interval after which results are logged ## Related Issue(s) - Resolves #157 ## Update - This PR has changed to consider a standard way of handling configuration files as well as command line arguments. It currently introduces functionality to create and parse the Cli from an optionally-provided config file, to merge this Cli with that parsed from command line arguments, and to grant precedence to the options/values in the latter. - Secondly, this PR also replaces the logging crate from simple_logger to flexi_logger. flexi_logger allows dynamic update of log levels after initialization and was required to deal with the issue described here. - Finally, documentation was updated to reflect the introduction and use of a config file. Note: There are some changes to unrelated files because of the requirement to wrap maximum width of code and comments at 120 column spaces. Thought to include them regardless following conversation from #164 on maintaining width.

enigbe added 7 commits March 11, 2024 12:47
- loads config options from a file and overwrites
with CLI args

- adds configurable log interval

-change configuration file type by doing the ffg:
replacing conf.json with conf.ini, updating
SimulationConfig::load(...) to read the new .ini
file, implementing cli_overwrite!(...) macro to
reduce LOC when overwriting config values with CLI
arguments
- Implements a Cli::from_config_file(...) method
to load configuration options from either a default
or user-provided (via command line argument) config
file

- Merges the Cli-s generated from the config file
and the parsed command line arguments taking into
account the following precedence
(command line args > configuration options > default value)

- deletes config.rs and the former implementation
that loads configuration options into a Simulation-
Config struct
- The latter allows dynamic, programmatic updates to the log level at runtime.

- The replace was necessary to capture and log command line arguments and configuration options which may or may not contain
specification of the log levels after parsing
- additionally reduces the LOC by implementing the
overwrite_field!(...) macro and from_config_field(...)
generic function.

- makes the requirement of a configuration file
optional, defaulting to default Cli values if no
config file is provided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants