Sfoglia il codice sorgente

changed bit ifelse() chain to a match/case

Pat Beirne 6 mesi fa
parent
commit
c61128f54c
1 ha cambiato i file con 37 aggiunte e 35 eliminazioni
  1. 37 35
      pwgen.py

+ 37 - 35
pwgen.py

@@ -94,43 +94,46 @@ def get_args(conf):
       sys.exit()
     elif a[0]=='-':
       for b in a[1:]:
-        if b=='c':
-          conf.first_punct = True
-        elif b=="C":
-          conf.last_punct = True
-        elif b=="n":
-          conf.first_number = True
-        elif b=='N': # add number
-          conf.last_number = True
-        elif b=='s':
-          conf.padding = Padding.spaces
-        elif b=='S':
-          conf.padding = Padding.dots
-        elif b=='p':
-          conf.padding = Padding.punct
-        elif b=='P':
-          conf.padding = Padding.numbers
-        elif b=='k':
-          conf.padding = Padding.camel
-        elif b=='K':
-          conf.padding = Padding.snake
-        elif b=='M': 
-          conf.capitalize = True  
-        elif b=='X':
-          conf.capitalize = True
-          conf.last_punct = True
-          conf.last_number = True
-          conf.padding = Padding.dots
-        elif b=="a":
-          conf.use_conjunctions = True;
-        elif b=="L":
-          narg = narg + 1
-          if narg < nargs:
-            conf.target_len = toInt(sys.argv[narg],[12,66],rangeStr = "Sorry, I can't build phrases that long")
-      
+        match b:
+          case 'c':
+            conf.first_punt = True
+          case 'C':
+            conf.last_punct = True
+          case 'n':
+            conf.first_number = True
+          case 'N':  # add number
+            conf.last_number = True
+          case 's':
+            conf.padding = Padding.spaces
+          case 'S':
+            conf.padding = Padding.dots
+          case 'p':
+            conf.padding = Padding.punct
+          case 'P':
+            conf.padding = Padding.numbers
+          case 'k':
+            conf.padding = Padding.camel
+          case 'K':
+            conf.padding = Padding.snake
+          case 'M': 
+            conf.capitalize = True  
+          case 'X':
+            conf.capitalize = True
+            conf.last_punct = True
+            conf.last_number = True
+            conf.padding = Padding.dots
+          case 'a':
+            conf.use_conjunctions = True;
+          case 'L':
+            narg = narg + 1
+            if narg < nargs:
+              conf.target_len = toInt(sys.argv[narg],[12,66],rangeStr = "Sorry, I can't build phrases that long")
+          case _:
+            print(f">>> unexpected command option '{b}'")      
     else:
       if narg < nargs:
         conf.number = toInt(sys.argv[narg],[0,40],rangeStr = "Sorry, I can't print that many; try a smaller number")  # pick off the number of phrases
+
     narg = narg + 1
 
 
@@ -250,4 +253,3 @@ NEW PLAN
 
 leet encoder a->4A e->3 i->I o->0 s->5$ t->7 
 """
-