From c61128f54cac6b3feedb66b2bb133871c9be76ac Mon Sep 17 00:00:00 2001 From: Pat Beirne Date: Tue, 7 May 2024 21:43:06 -0400 Subject: [PATCH] changed bit ifelse() chain to a match/case --- pwgen.py | 72 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/pwgen.py b/pwgen.py index 3d59612..a2d8659 100755 --- a/pwgen.py +++ b/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 """ -