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

User defined config file #30

Closed
infinity0n3 opened this issue Sep 8, 2017 · 3 comments · Fixed by #31
Closed

User defined config file #30

infinity0n3 opened this issue Sep 8, 2017 · 3 comments · Fixed by #31

Comments

@infinity0n3
Copy link

infinity0n3 commented Sep 8, 2017

When using add_config option and passing a custom filename for the config file it is not loaded.
app.add_config("-c,--config", "config.ini", "Read config from an ini file", false);
>> app --config custom_config.ini

Ini parsing code in App.hpp should be something like this to make it work.

        // Process an INI file
        if(config_ptr_ != nullptr && config_name_ != "") {
            auto user_config = config_ptr_->results();
            
            // take user passed filename into account
            if( config_ptr_->count() ) {
                config_name_ = config_ptr_->results()[0];
            }
            
            try {
                std::vector<detail::ini_ret_t> values = detail::parse_ini(config_name_);
                while(!values.empty()) {
                    if(!_parse_ini(values)) {
                        throw ExtrasINIError(values.back().fullname);
                    }
                }
            } catch(const FileError &) {
                if(config_required_)
                    throw;
            }
        }
@henryiii
Copy link
Collaborator

henryiii commented Sep 10, 2017

I implemented a similar fix, I just used the existing callback infrastructure (config_ptr_->run_callback()), and I also added a requirement that user-supplied names must be found. Also added the missing tests.

@henryiii
Copy link
Collaborator

It would be great if you could verify this fix works in your case, too!

@infinity0n3
Copy link
Author

Fix works great!

henryiii added a commit that referenced this issue Sep 10, 2017
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 a pull request may close this issue.

2 participants