-
Notifications
You must be signed in to change notification settings - Fork 19
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
Issue 2261/json config overridable cli #2325
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2745552
chore: programs options basic refactor
JakubFornadel 30c4415
chore: implement json config options parser
JakubFornadel f0ec7da
chore: move all config values into the config cli options and create …
JakubFornadel 65dd7ef
chore: all config values (except genesis) can be specified also throu…
JakubFornadel 094e600
chore: post merge fixes + local-net script fix
JakubFornadel 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
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
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 was deleted.
Oops, something went wrong.
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
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
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,117 @@ | ||
#pragma once | ||
|
||
#include <boost/program_options.hpp> | ||
#include <string> | ||
|
||
#include "cli/configs.hpp" | ||
#include "config/config.hpp" | ||
|
||
namespace taraxa::cli { | ||
|
||
class ConfigParser { | ||
public: | ||
enum class ChainIdType { Mainnet = 841, Testnet, Devnet, LastNetworkId }; | ||
static constexpr ChainIdType kDefaultChainId = ChainIdType::Mainnet; | ||
|
||
public: | ||
/** | ||
* @brief Creates FullNodeConfig based on provided command line arguments | ||
* | ||
* @return empty optional in case created config is invalid or specified command did not require config creation, | ||
* otherwise newly created and parsed config | ||
*/ | ||
std::optional<FullNodeConfig> createConfig(int argc, const char* argv[]); | ||
|
||
bool updateConfigFromJson(FullNodeConfig& config, const std::string& json_config_path); | ||
|
||
private: | ||
/** | ||
* @brief Registeres options that can be specified only through command line | ||
* | ||
* @return options_description | ||
*/ | ||
boost::program_options::options_description registerCliOnlyOptions(); | ||
|
||
/** | ||
* @brief Registeres options that can be specified in config as well as command line arguments | ||
* | ||
* @param config object into which are options directly parsed later on | ||
* @return options_description | ||
*/ | ||
boost::program_options::options_description registerCliConfigOptions(FullNodeConfig& config); | ||
|
||
/** | ||
* @brief Updates config based on json config values stored in file (json_config_path) | ||
* | ||
* @param config | ||
* @param json_config_path | ||
* @param genesis_path | ||
* @param wallet_path | ||
* @param cli_options | ||
*/ | ||
bool parseJsonConfigFiles(const boost::program_options::options_description& allowed_options, | ||
boost::program_options::variables_map& option_vars, FullNodeConfig& config, | ||
const std::string& json_config_path, std::optional<std::string> genesis_path = {}, | ||
std::optional<std::string> wallet_path = {}); | ||
|
||
/** | ||
* @brief Adds command line arguments values(those that are not also part of config arguments) to the config stucture | ||
* | ||
* @param config | ||
* @param override_boot_nodes | ||
* @param append_boot_nodes | ||
* @param enable_log_configurations | ||
* @param override_log_channels | ||
* @param log_channels_append | ||
* @param node_secret | ||
* @param vrf_secret | ||
*/ | ||
static void updateConfigFromCliSpecialOptions(FullNodeConfig& config, | ||
const std::vector<std::string>& override_boot_nodes, | ||
const std::vector<std::string>& append_boot_nodes, | ||
const std::vector<std::string>& enable_log_configurations, | ||
const std::vector<std::string>& override_log_channels, | ||
const std::vector<std::string>& append_log_channels, | ||
const std::string& node_secret, const std::string& vrf_secret); | ||
|
||
/** | ||
* @brief Adds config values that are not registered as config cmd options | ||
* | ||
* @param config | ||
* @param config_path | ||
* @param genesis_path | ||
* @param wallet_path | ||
*/ | ||
static void parseUnregisteredConfigOptionsValues(FullNodeConfig& config, const std::string& config_path, | ||
const std::optional<std::string>& genesis_path, | ||
const std::optional<std::string>& wallet_path); | ||
|
||
/** | ||
* @brief Generates default paths and configs in case provided paths are either empty or they dont exist | ||
* | ||
* @param chain_id | ||
* @param config_path | ||
* @param genesis_path | ||
* @param wallet_path | ||
*/ | ||
void generateDefaultPathsAndConfigs(ConfigParser::ChainIdType chain_id, std::string& config_path, | ||
std::string& genesis_path, std::string& wallet_path); | ||
|
||
private: | ||
// Cli or config options that cannot be parsed directly to the FullNodeConfig object due to some required additional | ||
// processing or incompatible types | ||
std::string genesis_path_, config_path_, wallet_path_, chain_str_, node_secret_, vrf_secret_; | ||
std::vector<std::string> command_, boot_nodes_, log_channels_, log_configurations_, boot_nodes_append_, | ||
log_channels_append_; | ||
|
||
int chain_id_{static_cast<int>(kDefaultChainId)}; | ||
bool overwrite_config_{false}; | ||
bool destroy_db_{false}; | ||
bool rebuild_network_{false}; | ||
|
||
std::string data_path_str_; | ||
uint64_t packets_stats_time_period_ms_{0}; | ||
uint64_t peer_max_packets_processing_time_us_{0}; | ||
}; | ||
|
||
} // namespace taraxa::cli |
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
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.
I do not know about this, e.g. geth as this disabled by default
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.
will change it to false