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

config file handling refactor #362

Merged
merged 1 commit into from
Dec 31, 2019
Merged

Conversation

phlptp
Copy link
Collaborator

@phlptp phlptp commented Dec 6, 2019

This PR if merged is an an overhaul of the configuration file system. It should be backwards compatible with the existing way things worked modulo actual bug fixes. The only default change was making the default to ignore extras in a configuration file.

This PR was driven by

The big changes

  • a configurable option in apps to allow them to be triggered by config files
  • Generalize the config-formatter with customization points for some characters like, the vector notation, the value separator, and comment character. (to easily allow things like some Windows config files which use ':' as a value separator in the ini files.)
  • Generalize the default reader to handle most TOML files (not embededed inline tables)
  • predefine a TOML output module
  • support option groups and grouping in the config output generator

refactor some of the configuration file handling code. Make it easier to get the actual file that was processed, and allow extras in the config file to be ignored(default now), captured or errored.

For handing of unrecognized options in ini files there are 3 options, ignore(now default), capture(forward to app missing), and error. The function specifying this can take a boolean(same behavior as before) or an enum. The default behavior has changed but the behavior of the function calls is the same as before.

Closes #363 (test included). Closes #214.

@codecov
Copy link

codecov bot commented Dec 6, 2019

Codecov Report

Merging #362 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #362    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files          12     12            
  Lines        3366   3552   +186     
======================================
+ Hits         3366   3552   +186
Impacted Files Coverage Δ
include/CLI/Validators.hpp 100% <100%> (ø) ⬆️
include/CLI/Config.hpp 100% <100%> (ø) ⬆️
include/CLI/Option.hpp 100% <100%> (ø) ⬆️
include/CLI/App.hpp 100% <100%> (ø) ⬆️
include/CLI/StringTools.hpp 100% <100%> (ø) ⬆️
include/CLI/ConfigFwd.hpp 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d5cd986...41bdc28. Read the comment docs.

@phlptp phlptp force-pushed the config_file_refactor branch 2 times, most recently from 7a86355 to b9db74a Compare December 29, 2019 13:51
@phlptp phlptp changed the title [WIP] config file handling refactor config file handling refactor Dec 30, 2019
@phlptp phlptp marked this pull request as ready for review December 30, 2019 15:26
@phlptp
Copy link
Collaborator Author

phlptp commented Dec 30, 2019

I think this is ready for a review.

@henryiii
Copy link
Collaborator

This is fantastic! I'll try to review tonight.

@phlptp phlptp mentioned this pull request Dec 30, 2019
3 tasks
Copy link
Collaborator

@henryiii henryiii left a comment

Choose a reason for hiding this comment

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

A few minor touchups recommended, otherwise it looks great.

Would it make sense to change the default in 2.0 to read and write TOML files, with INI being an option that has to be loaded? The formats are similar, and TOML is better defined than INI. I think vectors were not part of any INI format per say, and I came up with the current space separated method. So really the only difference is the comment character.

book/chapters/config.md Outdated Show resolved Hide resolved
book/chapters/config.md Show resolved Hide resolved
book/chapters/config.md Outdated Show resolved Hide resolved
book/chapters/config.md Outdated Show resolved Hide resolved
@phlptp
Copy link
Collaborator Author

phlptp commented Dec 31, 2019

I think it would make sense to make the write output TOML compliant in 2.0. I think as long as we leave the read side capable of reading both to the extent possible. But switching the write to TOML at some point makes a lot of sense.

@phlptp
Copy link
Collaborator Author

phlptp commented Dec 31, 2019

I think I would recommend a 1.9 release before making the switch though.

@henryiii
Copy link
Collaborator

I think we are close to a 1.9 release. I want to push that out soon then work on the precompile mode and Exception-free option, which are (my) two wishlist items for 2.0.

@henryiii
Copy link
Collaborator

Should have merged this before #382. Will fix issues and merge.

@phlptp
Copy link
Collaborator Author

phlptp commented Dec 31, 2019

I will work on #371 in the next day or so. That would be the last thing I want to deal with for the near term that effects our uses. If we can get that in before 1.9 then I use the main repo version in our code base instead of a customized one. I want to do some work on the book after that but I think that should be mostly separate from the major refactoring you are thinking of.

… to get the actual file that was processed, and allow extras in the config file to be ignored(default now), captured or errored.

fix std::error reference and formatting

add test for required but no default and fix a shadow warning on 'required' from gcc 4.8

Test correctness of config write-read loop

fix config generation for flag definitions

make the config output conform with toml

continue work on the config file interpretation and construction

get all the ini tests working again with the cleaned up features.

update formatting

rename IniTest to ConfigFileTest to better reflect actual tests and add a few more test of the configTOML
disambiguate enable/disable by default to an enumeration, and to make room for a configurable option to allow subcommands to be triggered by a config file.
add a ConfigBase class to generally reflect a broader class of configuration files formats of similar nature to INI files

add configurable to app and allow it to trigger subcommands

add test of ini formatting

add section support to the config files so sections can be opened and closed and the callbacks triggered as appropriate.

add handling of option groups to the config file output

add subcommand and option group configuration to config file output

subsubcom test on config files

fix a few sign comparison warnings and formatting

start working on the book edits for configuration and a few more tests

more test to check for subcommand close in config files

more tests for coverage

generalize section opening and closing

add more tests and some fixes for different configurations

yet more tests of different situations related to configuration files

test more paths for configuration file sections

remove some unused code and fix some codacy warnings

update readme with updates from configuration files

more book edits and README formatting

remove extra space

Apply suggestions from code review

Co-Authored-By: Henry Schreiner <HenrySchreinerIII@gmail.com>

fix some comments and documentation

fix spacing

Rename size_t -> std::size_t

Fix compiler warnings with -Wsign-conversion

Fix new warnings with -Wsign-conversion in PR
@henryiii
Copy link
Collaborator

Sounds good. Yes, that should not be touched by the restructure.

@henryiii henryiii merged commit c67ab9d into CLIUtils:master Dec 31, 2019
@henryiii henryiii deleted the config_file_refactor branch December 31, 2019 16:28
@henryiii
Copy link
Collaborator

Thanks!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants