Skip to content

Conversation

Firefly35
Copy link

@Firefly35 Firefly35 commented Dec 9, 2021

Using set_config will search for the config filename from the current run directory of the application.
When the file is not found in this situation, it is searched for from the config_root_folder when it is set.
This pull request fixes the #682 issue.

Loïc Touraine and others added 5 commits December 9, 2021 10:15
…g set_config will search for the config filename from the current run directory of the application, when the file is not found in this situation, it is searched for from the config_root_folder when it is set.
@phlptp
Copy link
Collaborator

phlptp commented Dec 13, 2021

I am not sure I like this change. Adding paths here seems problematic to me. One thing I could see being useful is making support in the config_file for a ';' separated list. So it could check down the list until it found one and use that one. That would be a little more general support and still give the flexibility that this PR is proposing without adding a new function signature.

@Firefly35
Copy link
Author

Firefly35 commented Dec 13, 2021 via email

@phlptp
Copy link
Collaborator

phlptp commented Dec 13, 2021

Might be just that the applications I work on are all cross platform so there is no standardized locations and having an absolute path in a binary that could be installed in countless different ways leads to all sorts of problems. Or even a relative one would have to defined in a per operating system basis due to different path formats in use on different operating systems.

I suppose that might be an applications problem vs a CLI11 problem though.

@Firefly35
Copy link
Author

Firefly35 commented Dec 13, 2021 via email

if(path_result == detail::path_type::nonexistent && !default_config_folder_.empty()) {
// Try to find the config file from its name in default config folder
std::string config_file_path = default_config_folder_;
if(default_config_folder_.back() != '/' && default_config_folder_.back() != '\\') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this check be better in the set_config function to only do it once rather than every element of a loop?

@phlptp
Copy link
Collaborator

phlptp commented Dec 13, 2021

Wow, and I thought we had a lot of options in our applications.

I am fine with it, let @henryiii decide to merge it if he thinks it appropriate.
I know we went through a lot of revisions into CLI11 to not have to use a custom version and get the needed changes merged in, so thanks,

@henryiii
Copy link
Collaborator

set_config's arguments change in a non-backward compatible way and there are no tests. But IMO this is not needed at all; can't you just add a transform to the option that injects the default folder? I'd much rather build things out of existing components vs. add new API, especially new API that is a positional argument (so unreadable). A nice test + docs for how to do it would be great, though.

@Firefly35
Copy link
Author

Firefly35 commented Jan 28, 2022

Did you look deeply to the PR ? set_config has always the previous API signature, and there is an overload with the additionnal default_config_root_folder argument.
Moreover, I don't see how I can put a transform option as the config_root_folder is needed to figure out the root folder to search the config for while using set_config, AFAIK this happens before any option is parsed.

@henryiii
Copy link
Collaborator

there is an overload

I missed the overload. But that makes this potentially confusing, as well, since not only are there no names on the arguments in C++, the order is not stable either.

Moreover, I don't see how I can put a transform option as the config_root_folder is needed to figure out the root folder to search the config for while using set_config, AFAIK this happens before any option is parsed.

Maybe we should try to fix that instead? At least I think we should carefully consider trying that path first. The config option is already special, so I think we could build on that.

@phlptp
Copy link
Collaborator

phlptp commented Jan 28, 2022

I kind of like Henry's idea of enabling validators and transforms on the config option. That is probably an oversight on our part. Then I think a built in transform that checks paths and if necessary adds a default path might be quite useful in other contexts as well.

@Firefly35
Copy link
Author

Firefly35 commented Jan 28, 2022 via email

@phlptp
Copy link
Collaborator

phlptp commented Jan 29, 2022

Just an update, transforms work fine on the config file option. They are executed before an options value gets used, which in the case of config is just before the file is processed, so a transform on the option from set_config works as expected and can be used.

@henryiii
Copy link
Collaborator

My worry was in teaching it / reading it; default arguments are easier, though they still require a user look them up, but different signatures require each signature to be documented, for readers to be familiar with both, and count parameters, etc. Not that it can't be handled by a compiler.

@phlptp
Copy link
Collaborator

phlptp commented Jan 31, 2022

I am going to close this as a similar capability was merged in #698.

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.

3 participants