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]*"`
This commit is contained in:
Chad H
2023-01-11 16:28:05 -08:00
committed by GitHub
parent d07ce54dd0
commit b07928353c

View File

@@ -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 = {}