from argparse import ArgumentParser
import sys

from plumbum.cmd import docker
from six.moves import input as raw_input

from dodo_commands import Dodo


def _args():
    parser = ArgumentParser()
    parser.add_argument('--user')
    parser.add_argument('name', nargs='?')
    args = Dodo.parse_args(parser)
    return args


if Dodo.is_main(__name__):
    args = _args()
    if not args.name:
        containers = [
            x for x in docker("ps", "--format", "{{.Names}}").split('\n') if x
        ]
        print("0 - exit")
        for idx, container in enumerate(containers):
            print("%d - %s" % (idx + 1, container))

        print("\nSelect a container: ")
        choice = int(raw_input()) - 1

        if choice == -1:
            sys.exit(0)

        args.name = containers[choice]

    Dodo.run([
        'docker',
        'exec',
        '-i',
        '-t',
    ] + (['--user', args.user] if args.user else []) + [
        args.name,
        '/bin/bash',
    ], )

@@ -253,76 +253,285 @@
 nt('
-name', nargs='?')%0A    args = Dodo.parse_args(parser)%0A    return args
+--find')%0A    parser.add_argument('name', nargs='?')%0A    parser.add_argument('--cmd')%0A    args = Dodo.parse_args(parser)%0A%0A    args.cmd = args.cmd or '/bin/bash'%0A%0A    return args%0A%0A%0Adef _containers():%0A    return %5Bx for x in docker(%22ps%22, %22--format%22, %22%7B%7B.Names%7D%7D%22).split('%5Cn') if x%5D
 %0A%0A%0Ai
@@ -579,28 +579,25 @@
 s()%0A
+%0A
     if 
-not 
 args.
-name
+find
 :%0A  
@@ -602,16 +602,20 @@
         
+for 
 containe
@@ -619,102 +619,184 @@
 iner
-s = %5B%0A            x for x in docker(%22ps%22, %22--format%22, %22%7B%7B.Names%7D%7D%22).split('%5Cn') if x%0A        %5D
+ in _containers():%0A            if args.find in container:%0A                args.name = container%0A                break%0A    elif not args.name:%0A        containers = _containers()
 %0A   
@@ -1254,27 +1254,24 @@
         
-'/bin/bash'
+args.cmd
 ,%0A    %5D,

Add --find flag to docker-exec