Support command-line overrides.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 27 Sep 2012 07:36:40 +0000 (03:36 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 27 Sep 2012 07:36:40 +0000 (03:36 -0400)
irkbot.py

index dfe8b684a64f5d4b525b3fbbce191c4985efa419..3abfbc40565a91a040b60ea9756e33d158bf4a5e 100755 (executable)
--- a/irkbot.py
+++ b/irkbot.py
 # short -> first 12 chars of hex ID
 # describe = -> describe relative to last tag, falling back to short
 # The default is 'describe'.
+#
+# Any of these variables can be overridden with a command-line argument that
+# is a key=value pair. For example "project=foobar" will force the project
+# name to foobar, regardless of what the git configuration says.
 
 # The default location of the irker proxy, if the project configuration
 # does not override it.
@@ -147,6 +151,22 @@ if __name__ == "__main__":
     # Someday we'll have extractors for several version-control systems
     extractor = GitExtractor(project)
 
+    # Make command-line overrides possible.
+    # Each argument of the form <key>=<value> can override the
+    # <key> member of the extractor class. 
+    booleans = ["tcp"]
+    for tok in arguments:
+        for key in extractor.__dict__:
+            if tok.startswith(key + "="):
+                val = tok[len(key)+1:]
+                if key in booleans:
+                    if val.lower == "true":
+                        setattr(extractor, key, True)
+                    elif val.lower == "false":
+                        setattr(extractor, key, False)
+                else:
+                    setattr(extractor, key, val)
+
     # By default, the channel list includes the freenode #commits list 
     if not extractor.channels:
         extractor.channels = "irc://chat.freenode.net/%s,irc://chat.freenode.net/#commits" % extractor.project