mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use bool instead of string for flags
This commit is contained in:
parent
279db68b46
commit
ab96da8eb2
2 changed files with 33 additions and 38 deletions
37
api.go
37
api.go
|
@ -150,8 +150,8 @@ func getImages(srv *Server, w http.ResponseWriter, r *http.Request) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
viz := r.Form.Get("viz")
|
viz := r.Form.Get("viz") == "1"
|
||||||
if viz == "1" {
|
if viz {
|
||||||
file, rwc, err := hijackServer(w)
|
file, rwc, err := hijackServer(w)
|
||||||
if file != nil {
|
if file != nil {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
@ -170,11 +170,11 @@ func getImages(srv *Server, w http.ResponseWriter, r *http.Request) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
all := r.Form.Get("all")
|
all := r.Form.Get("all") == "1"
|
||||||
filter := r.Form.Get("filter")
|
filter := r.Form.Get("filter")
|
||||||
quiet := r.Form.Get("quiet")
|
quiet := r.Form.Get("quiet") == "1"
|
||||||
|
|
||||||
outs, err := srv.Images(all, filter, quiet)
|
outs, err := srv.Images(all, quiet, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, err)
|
httpError(w, err)
|
||||||
return err
|
return err
|
||||||
|
@ -274,9 +274,9 @@ func getContainers(srv *Server, w http.ResponseWriter, r *http.Request) error {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
all := r.Form.Get("all")
|
all := r.Form.Get("all") == "1"
|
||||||
notrunc := r.Form.Get("notrunc")
|
notrunc := r.Form.Get("notrunc") == "1"
|
||||||
quiet := r.Form.Get("quiet")
|
quiet := r.Form.Get("quiet") == "1"
|
||||||
n, err := strconv.Atoi(r.Form.Get("n"))
|
n, err := strconv.Atoi(r.Form.Get("n"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n = -1
|
n = -1
|
||||||
|
@ -304,10 +304,7 @@ func postImagesTag(srv *Server, w http.ResponseWriter, r *http.Request) error {
|
||||||
tag := r.Form.Get("tag")
|
tag := r.Form.Get("tag")
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
name := vars["name"]
|
name := vars["name"]
|
||||||
var force bool
|
force := r.Form.Get("force") == "1"
|
||||||
if r.Form.Get("force") == "1" {
|
|
||||||
force = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := srv.ContainerTag(name, repo, tag, force); err != nil {
|
if err := srv.ContainerTag(name, repo, tag, force); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
@ -556,10 +553,8 @@ func deleteContainers(srv *Server, w http.ResponseWriter, r *http.Request) error
|
||||||
}
|
}
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
name := vars["name"]
|
name := vars["name"]
|
||||||
var v bool
|
v := r.Form.Get("v") == "1"
|
||||||
if r.Form.Get("v") == "1" {
|
|
||||||
v = true
|
|
||||||
}
|
|
||||||
if err := srv.ContainerDestroy(name, v); err != nil {
|
if err := srv.ContainerDestroy(name, v); err != nil {
|
||||||
httpError(w, err)
|
httpError(w, err)
|
||||||
return err
|
return err
|
||||||
|
@ -643,11 +638,11 @@ func postContainersAttach(srv *Server, w http.ResponseWriter, r *http.Request) e
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logs := r.Form.Get("logs")
|
logs := r.Form.Get("logs") == "1"
|
||||||
stream := r.Form.Get("stream")
|
stream := r.Form.Get("stream") == "1"
|
||||||
stdin := r.Form.Get("stdin")
|
stdin := r.Form.Get("stdin") == "1"
|
||||||
stdout := r.Form.Get("stdout")
|
stdout := r.Form.Get("stdout") == "1"
|
||||||
stderr := r.Form.Get("stderr")
|
stderr := r.Form.Get("stderr") == "1"
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
name := vars["name"]
|
name := vars["name"]
|
||||||
|
|
||||||
|
|
34
server.go
34
server.go
|
@ -136,10 +136,10 @@ func (srv *Server) ImagesViz(file *os.File) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) Images(all, filter, quiet string) ([]ApiImages, error) {
|
func (srv *Server) Images(all, quiet bool, filter string) ([]ApiImages, error) {
|
||||||
var allImages map[string]*Image
|
var allImages map[string]*Image
|
||||||
var err error
|
var err error
|
||||||
if all == "1" {
|
if all {
|
||||||
allImages, err = srv.runtime.graph.Map()
|
allImages, err = srv.runtime.graph.Map()
|
||||||
} else {
|
} else {
|
||||||
allImages, err = srv.runtime.graph.Heads()
|
allImages, err = srv.runtime.graph.Heads()
|
||||||
|
@ -160,7 +160,7 @@ func (srv *Server) Images(all, filter, quiet string) ([]ApiImages, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
delete(allImages, id)
|
delete(allImages, id)
|
||||||
if quiet != "1" {
|
if !quiet {
|
||||||
out.Repository = name
|
out.Repository = name
|
||||||
out.Tag = tag
|
out.Tag = tag
|
||||||
out.Id = TruncateId(id)
|
out.Id = TruncateId(id)
|
||||||
|
@ -175,7 +175,7 @@ func (srv *Server) Images(all, filter, quiet string) ([]ApiImages, error) {
|
||||||
if filter == "" {
|
if filter == "" {
|
||||||
for id, image := range allImages {
|
for id, image := range allImages {
|
||||||
var out ApiImages
|
var out ApiImages
|
||||||
if quiet != "1" {
|
if !quiet {
|
||||||
out.Repository = "<none>"
|
out.Repository = "<none>"
|
||||||
out.Tag = "<none>"
|
out.Tag = "<none>"
|
||||||
out.Id = TruncateId(id)
|
out.Id = TruncateId(id)
|
||||||
|
@ -201,7 +201,7 @@ func (srv *Server) DockerInfo() ApiInfo {
|
||||||
out.Containers = len(srv.runtime.List())
|
out.Containers = len(srv.runtime.List())
|
||||||
out.Version = VERSION
|
out.Version = VERSION
|
||||||
out.Images = imgcount
|
out.Images = imgcount
|
||||||
if os.Getenv("DEBUG") == "1" {
|
if os.Getenv("DEBUG") != "" {
|
||||||
out.Debug = true
|
out.Debug = true
|
||||||
out.NFd = getTotalUsedFds()
|
out.NFd = getTotalUsedFds()
|
||||||
out.NGoroutines = runtime.NumGoroutine()
|
out.NGoroutines = runtime.NumGoroutine()
|
||||||
|
@ -253,10 +253,10 @@ func (srv *Server) ContainerPort(name, privatePort string) (string, error) {
|
||||||
return "", fmt.Errorf("No such container: %s", name)
|
return "", fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) Containers(all, notrunc, quiet string, n int) []ApiContainers {
|
func (srv *Server) Containers(all, notrunc, quiet bool, n int) []ApiContainers {
|
||||||
var outs []ApiContainers = []ApiContainers{} //produce [] when empty instead of 'null'
|
var outs []ApiContainers = []ApiContainers{} //produce [] when empty instead of 'null'
|
||||||
for i, container := range srv.runtime.List() {
|
for i, container := range srv.runtime.List() {
|
||||||
if !container.State.Running && all != "1" && n == -1 {
|
if !container.State.Running && !all && n == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i == n {
|
if i == n {
|
||||||
|
@ -264,9 +264,9 @@ func (srv *Server) Containers(all, notrunc, quiet string, n int) []ApiContainers
|
||||||
}
|
}
|
||||||
var out ApiContainers
|
var out ApiContainers
|
||||||
out.Id = container.ShortId()
|
out.Id = container.ShortId()
|
||||||
if quiet != "1" {
|
if !quiet {
|
||||||
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
||||||
if notrunc != "1" {
|
if !notrunc {
|
||||||
command = Trunc(command, 20)
|
command = Trunc(command, 20)
|
||||||
}
|
}
|
||||||
out.Image = srv.runtime.repositories.ImageName(container.Image)
|
out.Image = srv.runtime.repositories.ImageName(container.Image)
|
||||||
|
@ -496,11 +496,11 @@ func (srv *Server) ContainerWait(name string) (int, error) {
|
||||||
return 0, fmt.Errorf("No such container: %s", name)
|
return 0, fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr string, file *os.File) error {
|
func (srv *Server) ContainerAttach(name string, logs, stream, stdin, stdout, stderr bool, file *os.File) error {
|
||||||
if container := srv.runtime.Get(name); container != nil {
|
if container := srv.runtime.Get(name); container != nil {
|
||||||
//logs
|
//logs
|
||||||
if logs == "1" {
|
if logs {
|
||||||
if stdout == "1" {
|
if stdout {
|
||||||
cLog, err := container.ReadLog("stdout")
|
cLog, err := container.ReadLog("stdout")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Debugf(err.Error())
|
Debugf(err.Error())
|
||||||
|
@ -508,7 +508,7 @@ func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr str
|
||||||
Debugf(err.Error())
|
Debugf(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if stderr == "1" {
|
if stderr {
|
||||||
cLog, err := container.ReadLog("stderr")
|
cLog, err := container.ReadLog("stderr")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Debugf(err.Error())
|
Debugf(err.Error())
|
||||||
|
@ -519,7 +519,7 @@ func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr str
|
||||||
}
|
}
|
||||||
|
|
||||||
//stream
|
//stream
|
||||||
if stream == "1" {
|
if stream {
|
||||||
if container.State.Ghost {
|
if container.State.Ghost {
|
||||||
return fmt.Errorf("Impossible to attach to a ghost container")
|
return fmt.Errorf("Impossible to attach to a ghost container")
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr str
|
||||||
cStdinCloser io.Closer
|
cStdinCloser io.Closer
|
||||||
)
|
)
|
||||||
|
|
||||||
if stdin == "1" {
|
if stdin {
|
||||||
r, w := io.Pipe()
|
r, w := io.Pipe()
|
||||||
go func() {
|
go func() {
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
|
@ -540,10 +540,10 @@ func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr str
|
||||||
cStdin = r
|
cStdin = r
|
||||||
cStdinCloser = file
|
cStdinCloser = file
|
||||||
}
|
}
|
||||||
if stdout == "1" {
|
if stdout {
|
||||||
cStdout = file
|
cStdout = file
|
||||||
}
|
}
|
||||||
if stderr == "1" {
|
if stderr {
|
||||||
cStderr = file
|
cStderr = file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue