Also renames --since-id/--before-id to --since/--before and add errors
on non-existent containers.
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
| ... | ... |
@@ -1337,8 +1337,8 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
| 1337 | 1337 |
all := cmd.Bool([]string{"a", "-all"}, false, "Show all containers. Only running containers are shown by default.")
|
| 1338 | 1338 |
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
|
| 1339 | 1339 |
nLatest := cmd.Bool([]string{"l", "-latest"}, false, "Show only the latest created container, include non-running ones.")
|
| 1340 |
- since := cmd.String([]string{"#sinceId", "-since-id"}, "", "Show only containers created since Id, include non-running ones.")
|
|
| 1341 |
- before := cmd.String([]string{"#beforeId", "-before-id"}, "", "Show only container created before Id, include non-running ones.")
|
|
| 1340 |
+ since := cmd.String([]string{"#sinceId", "#-since-id", "-since"}, "", "Show only containers created since Id or Name, include non-running ones.")
|
|
| 1341 |
+ before := cmd.String([]string{"#beforeId", "#-before-id", "-before"}, "", "Show only container created before Id or Name, include non-running ones.")
|
|
| 1342 | 1342 |
last := cmd.Int([]string{"n"}, -1, "Show n last created containers, include non-running ones.")
|
| 1343 | 1343 |
|
| 1344 | 1344 |
if err := cmd.Parse(args); err != nil {
|
| ... | ... |
@@ -392,11 +392,8 @@ _docker_port() |
| 392 | 392 |
_docker_ps() |
| 393 | 393 |
{
|
| 394 | 394 |
case "$prev" in |
| 395 |
- --since-id|--before-id) |
|
| 396 |
- COMPREPLY=( $( compgen -W "$( __docker_q ps -a -q )" -- "$cur" ) ) |
|
| 397 |
- # TODO replace this with __docker_containers_all |
|
| 398 |
- # see https://github.com/dotcloud/docker/issues/3565 |
|
| 399 |
- return |
|
| 395 |
+ --since|--before) |
|
| 396 |
+ __docker_containers_all |
|
| 400 | 397 |
;; |
| 401 | 398 |
-n) |
| 402 | 399 |
return |
| ... | ... |
@@ -407,7 +404,7 @@ _docker_ps() |
| 407 | 407 |
|
| 408 | 408 |
case "$cur" in |
| 409 | 409 |
-*) |
| 410 |
- COMPREPLY=( $( compgen -W "-q --quiet -s --size -a --all --no-trunc -l --latest --since-id --before-id -n" -- "$cur" ) ) |
|
| 410 |
+ COMPREPLY=( $( compgen -W "-q --quiet -s --size -a --all --no-trunc -l --latest --since --before -n" -- "$cur" ) ) |
|
| 411 | 411 |
;; |
| 412 | 412 |
*) |
| 413 | 413 |
;; |
| ... | ... |
@@ -154,13 +154,13 @@ complete -c docker -A -f -n '__fish_seen_subcommand_from port' -a '(__fish_print |
| 154 | 154 |
# ps |
| 155 | 155 |
complete -c docker -f -n '__fish_docker_no_subcommand' -a ps -d 'List containers' |
| 156 | 156 |
complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s a -l all -d 'Show all containers. Only running containers are shown by default.' |
| 157 |
-complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l before-id -d 'Show only container created before Id, include non-running ones.' |
|
| 157 |
+complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l before -d 'Show only container created before Id or Name, include non-running ones.' |
|
| 158 | 158 |
complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s l -l latest -d 'Show only the latest created container, include non-running ones.' |
| 159 | 159 |
complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s n -d 'Show n last created containers, include non-running ones.' |
| 160 | 160 |
complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l no-trunc -d "Don't truncate output" |
| 161 | 161 |
complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s q -l quiet -d 'Only display numeric IDs' |
| 162 | 162 |
complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -s s -l size -d 'Display sizes' |
| 163 |
-complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l since-id -d 'Show only containers created since Id, include non-running ones.' |
|
| 163 |
+complete -c docker -A -f -n '__fish_seen_subcommand_from ps' -l since -d 'Show only containers created since Id or Name, include non-running ones.' |
|
| 164 | 164 |
|
| 165 | 165 |
# pull |
| 166 | 166 |
complete -c docker -f -n '__fish_docker_no_subcommand' -a pull -d 'Pull an image or a repository from the docker registry server' |
| ... | ... |
@@ -967,13 +967,13 @@ new output from the container's stdout and stderr. |
| 967 | 967 |
List containers |
| 968 | 968 |
|
| 969 | 969 |
-a, --all=false: Show all containers. Only running containers are shown by default. |
| 970 |
- --before-id="": Show only container created before Id, include non-running ones. |
|
| 970 |
+ --before="": Show only container created before Id or Name, include non-running ones. |
|
| 971 | 971 |
-l, --latest=false: Show only the latest created container, include non-running ones. |
| 972 | 972 |
-n=-1: Show n last created containers, include non-running ones. |
| 973 | 973 |
--no-trunc=false: Don't truncate output |
| 974 | 974 |
-q, --quiet=false: Only display numeric IDs |
| 975 | 975 |
-s, --size=false: Display sizes, not to be used with -q |
| 976 |
- --since-id="": Show only containers created since Id, include non-running ones. |
|
| 976 |
+ --since="": Show only containers created since Id or Name, include non-running ones. |
|
| 977 | 977 |
|
| 978 | 978 |
|
| 979 | 979 |
Running ``docker ps`` showing 2 linked containers. |
| ... | ... |
@@ -981,12 +981,27 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
|
| 981 | 981 |
return nil |
| 982 | 982 |
}, -1) |
| 983 | 983 |
|
| 984 |
+ var beforeCont, sinceCont *runtime.Container |
|
| 985 |
+ if before != "" {
|
|
| 986 |
+ beforeCont = srv.runtime.Get(before) |
|
| 987 |
+ if beforeCont == nil {
|
|
| 988 |
+ return job.Error(fmt.Errorf("Could not find container with name or id %s", before))
|
|
| 989 |
+ } |
|
| 990 |
+ } |
|
| 991 |
+ |
|
| 992 |
+ if since != "" {
|
|
| 993 |
+ sinceCont = srv.runtime.Get(since) |
|
| 994 |
+ if sinceCont == nil {
|
|
| 995 |
+ return job.Error(fmt.Errorf("Could not find container with name or id %s", since))
|
|
| 996 |
+ } |
|
| 997 |
+ } |
|
| 998 |
+ |
|
| 984 | 999 |
for _, container := range srv.runtime.List() {
|
| 985 | 1000 |
if !container.State.IsRunning() && !all && n <= 0 && since == "" && before == "" {
|
| 986 | 1001 |
continue |
| 987 | 1002 |
} |
| 988 | 1003 |
if before != "" && !foundBefore {
|
| 989 |
- if container.ID == before || utils.TruncateID(container.ID) == before {
|
|
| 1004 |
+ if container.ID == beforeCont.ID {
|
|
| 990 | 1005 |
foundBefore = true |
| 991 | 1006 |
} |
| 992 | 1007 |
continue |
| ... | ... |
@@ -994,8 +1009,10 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
|
| 994 | 994 |
if n > 0 && displayed == n {
|
| 995 | 995 |
break |
| 996 | 996 |
} |
| 997 |
- if container.ID == since || utils.TruncateID(container.ID) == since {
|
|
| 998 |
- break |
|
| 997 |
+ if since != "" {
|
|
| 998 |
+ if container.ID == sinceCont.ID {
|
|
| 999 |
+ break |
|
| 1000 |
+ } |
|
| 999 | 1001 |
} |
| 1000 | 1002 |
displayed++ |
| 1001 | 1003 |
out := &engine.Env{}
|