Skip to content

Commit b079283

Browse files
authored
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]*"`
1 parent d07ce54 commit b079283

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

autocompose.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#! /usr/bin/env python3
22
import argparse
33
import datetime
4+
import re
45
import sys
56

67
from collections import OrderedDict
@@ -77,13 +78,23 @@ def main():
7778
action="store_true",
7879
help="Create new volumes instead of reusing existing ones",
7980
)
81+
parser.add_argument(
82+
"-f",
83+
"--filter",
84+
type=str,
85+
help="Filter containers by regex",
86+
)
8087
args = parser.parse_args()
8188

8289
container_names = args.cnames
8390

8491
if args.all:
8592
container_names.extend(list_container_names())
8693

94+
if args.filter:
95+
cfilter = re.compile(args.filter)
96+
container_names = [c for c in container_names if cfilter.search(c)]
97+
8798
struct = {}
8899
networks = {}
89100
volumes = {}

0 commit comments

Comments
 (0)