mirror of
https://github.com/Red5d/docker-autocompose
synced 2026-01-08 01:28:03 +00:00
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:
@@ -1,6 +1,7 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
@@ -77,6 +78,12 @@ def main():
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Create new volumes instead of reusing existing ones",
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
container_names = args.cnames
|
container_names = args.cnames
|
||||||
@@ -84,6 +91,10 @@ def main():
|
|||||||
if args.all:
|
if args.all:
|
||||||
container_names.extend(list_container_names())
|
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 = {}
|
struct = {}
|
||||||
networks = {}
|
networks = {}
|
||||||
volumes = {}
|
volumes = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user