if-else -> match-case
@@ -125,13 +125,14 @@ class BrewInfo:
brew_taps = []
other_taps = []
for t in self.tap_list:
- if t == "homebrew/core":
+ match t:
+ case "homebrew/core":
core_tap.append(t)
- elif t == self.helper.opt["cask_repo"]:
+ case s if s == self.helper.opt["cask_repo"]:
cask_tap.append(t)
- elif t.startswith("homebrew/"):
+ case s if s.startswith("homebrew/"):
brew_taps.append(t)
- else:
+ case _:
other_taps.append(t)
brew_taps.sort()
other_taps.sort()
@@ -250,43 +251,44 @@ class BrewInfo:
if '"' in line or "'" in line:
self.helper.opt["form"] = "bundle"
- if cmd in ("brew", "install"):
+ match cmd.lower():
+ case "brew" | "install":
self.brew_input.append(p)
self.brew_input_opt[p] = opt
- elif cmd == "tap":
+ case "tap":
self.tap_input.append(p)
- elif cmd == "tapall":
+ case "tapall":
self.tap_input.append(p)
for tp in self.get_tap_packs(p):
self.brew_input.append(tp)
self.brew_input_opt[tp] = ""
for tp in self.get_tap_casks(p):
self.cask_input.append(tp)
- elif cmd == "cask":
+ case "cask":
self.cask_input.append(p)
- elif cmd == "mas" and line.find(",") != -1:
+ case s if s == "mas" and line.find(",") != -1:
if not self.helper.opt.get("form"):
self.helper.opt["form"] = "bundle"
p = line.split()[1].strip(",").strip("'").strip('"')
pid = line.split()[3]
self.appstore_input.append(pid + " " + p)
- elif cmd in ("appstore", "mas"):
+ case "appstore" | "mas":
self.appstore_input.append(
re.sub("^ *appstore *", "", line)
.strip()
.strip("'")
.strip('"')
)
- elif cmd == "main":
+ case "main":
self.main_input.append(p)
self.file_input.append(p)
- elif cmd == "file" or cmd.lower() == "brewfile":
+ case "file" | "brewfile":
self.file_input.append(p)
- elif cmd == "before":
+ case "before":
self.before_input.append(excmd)
- elif cmd == "after":
+ case "after":
self.after_input.append(excmd)
- elif cmd == "cask_args":
+ case "cask_args":
if self.helper.opt.get("form") in [
"brewdler",
"bundle",
@@ -302,7 +304,7 @@ class BrewInfo:
k = arg.split(":")[0]
v = arg.split("=")[1] if "=" in arg else ""
self.cask_args_input[k] = v
- else:
+ case _:
self.cmd_input.append(line.strip())
def get_tap_path(self, tap: str) -> Path:
