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

Get loaded config file name #293

Closed
Bouska opened this issue Jun 13, 2019 · 0 comments · Fixed by #362
Closed

Get loaded config file name #293

Bouska opened this issue Jun 13, 2019 · 0 comments · Fixed by #362

Comments

@Bouska
Copy link

Bouska commented Jun 13, 2019

For logging reasons, I want to retrieve the loaded config filename. One solution would been to have a access to the config_name_ variable but even then, if the default filename wasn't accessible, I wouldn't know (if the parameter config_required was not set).

Currently I have the following hack to get that information but it's pretty ugly:

    std::shared_ptr<CLI::App> _app = std::make_shared<CLI::App>("App");
    std::string _config_name = "./config.ini";
    _app->set_config("--config",
                   _config_name,
                   "Read a config file",
                   false);
    _config_name = (_app->get_option("--config")->results().empty())?_config_name:_app->get_option("--config")->results().at(0);
    std::ifstream test{_config_name};
    _config_name = (!test.good())?"None":_config_name;

It would be nice to have a nicer way to do that.

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.

1 participant