chiark / gitweb /
make-secnet-sites: Introduce new OpMod classes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 4 Dec 2019 16:06:58 +0000 (16:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 15 Feb 2020 21:56:53 +0000 (21:56 +0000)
This is going to replace the use of the `service' boolean.
Mode-specific functionality will be moved into these classes.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
make-secnet-sites

index 9e4538b..46a887c 100755 (executable)
@@ -290,7 +290,19 @@ class PkmElide(PkmBase):
        def site_finish(self,confw):
                confw.write("peer-keys \"%s\";\n"%self._pa);
 
+class OpBase():
+       pass
+
+class OpConf(OpBase):
+       def is_service(self): return 0
+
+class OpUserv(OpBase):
+       opts = ['--userv','-u']
+       help = 'userv service fragment update mode'
+       def is_service(self): return 1
+
 def parse_args():
+       global opmode
        global service
        global inputfile
        global header
@@ -308,8 +320,12 @@ def parse_args():
        global pubkeys_mode
 
        ap = argparse.ArgumentParser(description='process secnet sites files')
-       ap.add_argument('--userv', '-u', action='store_true',
-                       help='userv service fragment update mode')
+       def add_opmode(how):
+               ap.add_argument(*how().opts, action=ArgActionLambda,
+                       nargs=0,
+                       fn=(lambda v,ns,*x: setattr(ns,'opmode',how)),
+                       help=how().help)
+       add_opmode(OpUserv)
        ap.add_argument('--conf-key-prefix', action=ActionNoYes,
                        default=True,
                 help='prefix conf file key names derived from sites data')
@@ -334,7 +350,8 @@ def parse_args():
        av = ap.parse_args()
        debug_level = av.debug
        debugrepr('av',av)
-       service = 1 if av.userv else 0
+       opmode = getattr(av,'opmode',OpConf)()
+       service = opmode.is_service()
        prefix = '' if av.prefix is None else av.prefix[0]
        key_prefix = av.conf_key_prefix
        output_version = av.output_version[0]