move clickhouse-format code from settings to format.cpp

This commit is contained in:
taiyang-li 2022-02-07 13:34:13 +08:00
parent caed1898b0
commit 26f2a0ef51
3 changed files with 5 additions and 19 deletions

View File

@ -58,7 +58,11 @@ int mainEntryClickHouseFormat(int argc, char ** argv)
;
Settings cmd_settings;
cmd_settings.addFormatOptions(desc);
for (const auto & field : cmd_settings.all())
{
if (field.getName() == "max_parser_depth" || field.getName() == "max_query_size")
cmd_settings.addProgramOption(desc, field);
}
boost::program_options::variables_map options;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);

View File

@ -89,16 +89,6 @@ void Settings::addProgramOptions(boost::program_options::options_description & o
}
}
void Settings::addFormatOptions(boost::program_options::options_description & options)
{
for (const auto & field : all())
{
const auto & name = field.getName();
if (formatSettingNames.count(name))
addProgramOption(options, field);
}
}
void Settings::addProgramOption(boost::program_options::options_description & options, const SettingFieldRef & field)
{
const std::string_view name = field.getName();

View File

@ -712,21 +712,13 @@ struct Settings : public BaseSettings<SettingsTraits>, public IHints<2, Settings
/// (Don't forget to call notify() on the `variables_map` after parsing it!)
void addProgramOptions(boost::program_options::options_description & options);
/// Adds program options for clickhouse-format to set the settings from a command line.
/// (Don't forget to call notify() on the `variables_map` after parsing it!)
void addFormatOptions(boost::program_options::options_description & options);
/// Check that there is no user-level settings at the top level in config.
/// This is a common source of mistake (user don't know where to write user-level setting).
static void checkNoSettingNamesAtTopLevel(const Poco::Util::AbstractConfiguration & config, const String & config_path);
std::vector<String> getAllRegisteredNames() const override;
private:
void addProgramOption(boost::program_options::options_description & options, const SettingFieldRef & field);
inline static const std::unordered_set<String> formatSettingNames
= {"max_parser_depth", "max_query_size"};
};
/*