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

Enable option to read config from specific file #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chaserhkj
Copy link

Enable -f option for user to specify a file as the config to read from

alex-courtis
alex-courtis previously approved these changes Jun 7, 2022
Copy link
Owner

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Looks good, works.

Thanks for the contribution.

Please add new option to:

  • README.md

@@ -126,6 +128,12 @@ void parseArgs(int argc, char **argv, Settings &settings) {
case 'i':
settings.info = true;
break;
case 'f':
{
ifstream ifs(optarg);
Copy link
Owner

Choose a reason for hiding this comment

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

Please test ifs and error/exit if not found.

Something simple like "config file /path/to/.xlayoutdisplay not found, exiting"

@alex-courtis alex-courtis dismissed their stale review June 7, 2022 00:45

wrong category

Copy link
Owner

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Looks good, works.

Thanks for the contribution.

@@ -126,6 +128,12 @@ void parseArgs(int argc, char **argv, Settings &settings) {
case 'i':
settings.info = true;
break;
case 'f':
{
ifstream ifs(optarg);
Copy link
Owner

Choose a reason for hiding this comment

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

Please test ifs and error/exit if not found.

Something simple like "config file /path/to/.xlayoutdisplay not found, exiting"

case 'f':
{
ifstream ifs(optarg);
parseCfgFile(ifs, settings);
Copy link
Owner

@alex-courtis alex-courtis Jun 7, 2022

Choose a reason for hiding this comment

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

Settings from the default config files will be present. Any settings from the defaults that are not present in this file will still remain in the settings. Also, depending on invocation order, command line arguments may be overridden by the settings file.

Possible solutions:

  • destroy existing settings before reading -f
  • do not read default files when -f
  • read file and CLI settings separately then merge them

First two would require a "two pass" approach to reading arguments, the first lookng for -f and reading it prior to parsing the rest of the command line arguments.

@alex-courtis
Copy link
Owner

I'll merge this one after #20

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.

2 participants