From 994df7ac9c821aacd2a4ec4b5311530f8d11bc08 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 10 Jan 2023 21:50:51 -0800 Subject: [PATCH] Filter containers via regex Allows for dumping a subset of all containers without having to list them all explicitly. `autocompose.py --all --filter "foo-[0-9]*"` --- autocompose.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/autocompose.py b/autocompose.py index acc99a9e..a25f8e3a 100644 --- a/autocompose.py +++ b/autocompose.py @@ -1,6 +1,7 @@ #! /usr/bin/env python3 import argparse import datetime +import re import sys from collections import OrderedDict @@ -77,6 +78,12 @@ def main(): action="store_true", help="Create new volumes instead of reusing existing ones", ) + parser.add_argument( + "-f", + "--filter", + type=str, + help="Filter containers by regex", + ) args = parser.parse_args() container_names = args.cnames @@ -84,6 +91,10 @@ def main(): if args.all: container_names.extend(list_container_names()) + if args.filter: + cfilter = re.compile(args.filter) + container_names = [c for c in container_names if cfilter.search(c)] + struct = {} networks = {} volumes = {}