theappbusiness / ConfigGenerator

Configuration file code generator for use in Xcode projects
MIT License
157 stars 19 forks source link

Overriding values or inheriting from another plist #43

Open Jon889 opened 4 years ago

Jon889 commented 4 years ago

We've come across a situation where we have a config that needs to be identical to another one (and stay identical if changes are made) except for one value

Currently I'm using plutil to override the value just before calling configen but this is quite hacky. So I see there are two options:

Allow overriding a key value on the command line, eg:

configen -p "$configLocation" -h "$configDir/Config.map" -n $configName -o "$configDir" --override KEY VALUE

Inheriting from another plist, eg:

baseconfig.plist

<dict>
  <key>KEY1</key>
  <string>VALUE1</string>
  <key>KEY2</key>
  <string>VALUE2</string>
</dict>

config.plist:

<dict>
  <key>:super</key>
  <string>baseconfig.plist</string>
  <key>KEY2</key>
  <string>NEW_VALUE2</string>
</dict>

The key of the base plist being something like :super, :inherit_from or :base etc. But starting with a character like : that makes it an invalid swift variable name.

That way the generated config.swift from config.plist is:

class Config {
  static let KEY1 = "VALUE1"
  static let KEY2 = "NEW_VALUE2"
}

I think the latter plist inheritance option would be preferable as it keeps all the values in the plists and there's no chance of one hiding in a script somewhere. Would this be desirable to implement and create a pull request?

theblixguy commented 4 years ago

I think it's a good idea, but have you considered having two plist files (and changing the values you want to be different in the other plist file) and switching between them?

(I'm sure you have, but just asking anyway. I am interesting in learning about the reasons why that is not preferable in your scenario, apart from things getting duplicated).