-
Notifications
You must be signed in to change notification settings - Fork 384
Add the ability to set a config root folder in set_config #684
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
Conversation
…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.
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. |
In fact this functionality is a rather good solution for tools that host
several configurations in a $home/.app/configs/...
Calling the tool anywhere from the command line and switching config can -
with the PR - just use the config "name" instead of providing full paths to
every config file.
It's a common pattern for command line tools to have a centralized
configurations/profiles folder hosted in a "root" config folder.
For the moment I maintain my own fork, but I'd prefer if in a way or
another the functionality makes its way in CLI11.
Why do you find adding a "standardized path" searched for when the config
file was not found from its filepath is problematic ?
Le lun. 13 déc. 2021 à 18:14, Philip Top ***@***.***> a
écrit :
… 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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#684 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5Z2FC6DVZG5R43TMFXBKDUQYSYPANCNFSM5JV7CMYA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
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. |
Indeed. And the root path built is per os (in fact the same on unixes
including Linux and macos, but the home dir is built differently for
windows).
You can refer to the remaken application to see how I set it (see
CmdOptions.cpp) here
https://github.com/b-com-software-basis/remaken/tree/release/1.9.x
Le lun. 13 déc. 2021 à 22:27, Philip Top ***@***.***> a
écrit :
… 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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#684 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5Z2FDTV32B4444HL6ZCUTUQZQN7ANCNFSM5JV7CMYA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
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() != '\\') { |
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.
would this check be better in the set_config
function to only do it once rather than every element of a loop?
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. |
|
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. |
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.
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. |
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. |
I let you choose the best way to provide this feature in future CLI11
releases.
For now, we live with the workaround I quickly implemented :).
Concerning overloading in C++, there is IMHO no issue about arguments as
the method signature differs on the number and kind of arguments.
I don't think there can be any ambiguity between f(str,str,cstr,bool) and
f(str,str,cstr,cstr,bool) ?
Argument order would change if the calling convention was changed at
compile time, but as CLI11 is header only the calling convention would be
the same throughout the translation unit,
so I don't get where the argument order would be an issue ? (provided the
calling convention is the same in all libs/applications, but with different
calling conventions, not only CLI11 would be impacted, every argument
forwarding between the app and library would be impacted, no ?)
Le ven. 28 janv. 2022 à 17:47, Philip Top ***@***.***> a
écrit :
… 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.
—
Reply to this email directly, view it on GitHub
<#684 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5Z2FHQHPMOVXAQ3JAFWE3UYLCBRANCNFSM5JV7CMYA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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. |
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. |
I am going to close this as a similar capability was merged in #698. |
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.