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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void usage(std::ostream &os) {
"CLI:\n"
"-h [ --help ] print this help text and exit\n"
"-i [ --info ] print information about current outputs and exit\n"
"-f [ --file ] arg use file as config\n"
"-n [ --noop ] perform a trial run and exit\n"
"-v [ --version ] print version string\n"
"\n"
Expand Down Expand Up @@ -99,6 +100,7 @@ void parseArgs(int argc, char **argv, Settings &settings) {
static struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "info", no_argument, 0, 'i' },
{ "file", required_argument, 0, 'f' },
{ "noop", no_argument, 0, 'n' },
{ "version", no_argument, 0, 'v' },
{ "dpi", required_argument, 0, 'd' },
Expand All @@ -109,7 +111,7 @@ void parseArgs(int argc, char **argv, Settings &settings) {
{ "quiet", no_argument, 0, 'q' },
{ 0, 0, 0, 0 }
};
static const char *short_options = "hinvd:r:mo:p:q";
static const char *short_options = "hif:nvd:r:mo:p:q";

bool orderFromFile = !settings.order.empty();

Expand All @@ -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"

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"

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.

}
break;
case 'n':
settings.noop = true;
break;
Expand Down