package org.voovan.docker.command.Image;

import org.voovan.docker.command.Cmd;
import org.voovan.docker.message.Image.ImageListInfo;
import org.voovan.docker.network.DockerClientException;
import org.voovan.docker.network.Result;
import org.voovan.tools.TObject;
import org.voovan.tools.json.JSON;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 类文字命名
 *
 * @author helyho
 *         <p>
 *         JDocker Framework.
 *         WebSite: https://github.com/helyho/JDocker
 *         Licence: Apache v2 License
 */
public class CmdImageListInfo extends Cmd {

    private Map<String,List<String>> filters;

    public CmdImageListInfo() {
        filters = new HashMap<String,List<String>>();
    }

    public CmdImageListInfo all(Boolean all){
        addParameter("all",all);
        return this;
    }

    public CmdImageListInfo dangling(Boolean dangling){
        filters.put("dangling",TObject.newList(dangling));
        return this;
    }

    public CmdImageListInfo label(String key, Object value){
        filters.put("label", TObject.newList(key+"="+value));
        return this;
    }

    public CmdImageListInfo before(String ... before){
        addParameter("before",TObject.newList(before));
        return this;
    }

    public CmdImageListInfo since(String ... since){
        addParameter("since",TObject.newList(since));
        return this;
    }

    public static CmdImageListInfo newInstance() {
        return new CmdImageListInfo();
    }

    @Override
    public List<ImageListInfo> send() throws Exception {
        addParameter("filters", JSON.toJSON(filters));
        Result result = getDockerHttpClient().get("/images/json",getParameters());
        if(result.getStatus()>=300){
            throw new DockerClientException(result.getMessage());
        }else{
            return ImageListInfo.load(result.getMessage());
        }

    }
}

@@ -1189,28 +1189,27 @@
         
-addParameter
+filters.put
 (%22before
@@ -1313,24 +1313,160 @@
 ... since)%7B%0A
+        filters.put(%22since%22,TObject.newList(since));%0A        return this;%0A    %7D%0A%0A    public CmdImageListInfo filter(String ... filter)%7B%0A
         addP
@@ -1475,21 +1475,22 @@
 ameter(%22
-since
+filter
 %22,TObjec
@@ -1491,37 +1491,38 @@
 TObject.newList(
-since
+filter
 ));%0A        retu

修复 CmdImageList 关于 filters 的 bug