From b07928353c4e6139d17e34a93db84867714a4891 Mon Sep 17 00:00:00 2001 From: Chad H Date: Wed, 11 Jan 2023 16:28:05 -0800 Subject: [PATCH] Filter containers via regex (#57) 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 acc99a9..a25f8e3 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 = {}