Skip to content

Conversation

@Scraniel
Copy link

@Scraniel Scraniel commented Dec 8, 2022

This change adds a config-path parameter to the program that allows for a custom config file path instead of just the current or home directory. A passed in config file will cause the program to skip loading files in either the current or home directory. Other config flags passed in still take priority over values in the custom config.

This was accomplished by:

  1. Creating startupFlags, which is just a configuration struct with with a string tacked on for the ConfigPath.
  2. Splitting addFlags(config *configuration) into parseFlags() startupFlags and addFlags(flags startupFlags, config *configuration).
    • parseFlags simply reads in the flags so we know ConfigPath ahead of loading the config file
    • addFlags overwrites any values in the config with those passed in as flags
  3. Passing ConfigPath to loadConfigs
    • As mentioned before, passed in config takes priority over files in ~ and .

I also did a small refactor of the flag parsing, changing from using flags.String across the board to flags.StringVar and flags.IntVar to avoid additional conversion from string to int. I will change this back if there are strong opinions about the previous parsing method.

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.

1 participant