advent-of-code-downloader icon indicating copy to clipboard operation
advent-of-code-downloader copied to clipboard

feat: adding `config-path` flag

Open Scraniel opened this issue 2 years ago • 0 comments

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.

Scraniel avatar Dec 08 '22 07:12 Scraniel