Mostrando la salida de `cabal-plan` visualmente
Cuando corremos cabal plan diff hay mucho ruido en la salida. Este script de python muestra la salida mucho más accesible: #!/usr/bin/env python3 """Summarize the `Package versions` section of `cabal-plan diff` output. Pipe `cabal-plan diff` (or similar) output to this script. It extracts the section between the `Package versions` and `Dependency graph` headers, then prints: pkg-name oldver -> newver # for packages that changed new pkg-name ver # for packages only on the + side deleted pkg-name ver # for packages only on the - side """ import re import sys LINE_RE = re.compile(r"^\s*([-+])(\S+?)-(\d[\w.]*)\s") def parse(stream): in_section = False removed: dict[str, str] = {} added: dict[str, str] = {} for line in stream: stripped = line.strip() if stripped.startswith("Package versions"): in_section = True continue if stripped.startswith("Dependency graph"): break if not in_section: continue m = LINE_RE.match(line) if not m: continue sign, name, version = m.group(1), m.group(2), m.group(3) (removed if sign == "-" else added)[name] = version return removed, added def main() -> int: removed, added = parse(sys.stdin) changed_names = sorted(set(removed) & set(added)) only_removed = sorted(set(removed) - set(added)) only_added = sorted(set(added) - set(removed)) name_w = max( (len(n) for n in changed_names + only_added + only_removed), default=0, ) old_w = max((len(removed[n]) for n in changed_names), default=0) for name in changed_names: print(f"{name:<{name_w}} {removed[name]:<{old_w}} -> {added[name]}") if only_added: print() for name in only_added: print(f"new {name:<{name_w}} {added[name]}") if only_removed: print() for name in only_removed: print(f"deleted {name:<{name_w}} {removed[name]}") return 0 if __name__ == "__main__": sys.exit(main()) Se usa pasando la entrada en una tubería: ...