1
0
Fork 0
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:
Guillaume J. Charmes 2013-05-07 16:47:43 -07:00
parent 279db68b46
commit ab96da8eb2
2 changed files with 33 additions and 38 deletions

37
api.go
View file

@ -150,8 +150,8 @@ func getImages(srv *Server, w http.ResponseWriter, r *http.Request) error {
return err
}
viz := r.Form.Get("viz")
if viz == "1" {
viz := r.Form.Get("viz") == "1"
if viz {
file, rwc, err := hijackServer(w)
if file != nil {
defer file.Close()
@ -170,11 +170,11 @@ func getImages(srv *Server, w http.ResponseWriter, r *http.Request) error {
return nil
}
all := r.Form.Get("all")
all := r.Form.Get("all") == "1"
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 {
httpError(w, 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)
return err
}
all := r.Form.Get("all")
notrunc := r.Form.Get("notrunc")
quiet := r.Form.Get("quiet")
all := r.Form.Get("all") == "1"
notrunc := r.Form.Get("notrunc") == "1"
quiet := r.Form.Get("quiet") == "1"
n, err := strconv.Atoi(r.Form.Get("n"))
if err != nil {
n = -1
@ -304,10 +304,7 @@ func postImagesTag(srv *Server, w http.ResponseWriter, r *http.Request) error {
tag := r.Form.Get("tag")
vars := mux.Vars(r)
name := vars["name"]
var force bool
if r.Form.Get("force") == "1" {
force = true
}
force := r.Form.Get("force") == "1"
if err := srv.ContainerTag(name, repo, tag, force); err != nil {
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)
name := vars["name"]
var v bool
if r.Form.Get("v") == "1" {
v = true
}
v := r.Form.Get("v") == "1"
if err := srv.ContainerDestroy(name, v); err != nil {
httpError(w, 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)
return err
}
logs := r.Form.Get("logs")
stream := r.Form.Get("stream")
stdin := r.Form.Get("stdin")
stdout := r.Form.Get("stdout")
stderr := r.Form.Get("stderr")
logs := r.Form.Get("logs") == "1"
stream := r.Form.Get("stream") == "1"
stdin := r.Form.Get("stdin") == "1"
stdout := r.Form.Get("stdout") == "1"
stderr := r.Form.Get("stderr") == "1"
vars := mux.Vars(r)
name := vars["name"]

View file

@ -136,10 +136,10 @@ func (srv *Server) ImagesViz(file *os.File) error {
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 err error
if all == "1" {
if all {
allImages, err = srv.runtime.graph.Map()
} else {
allImages, err = srv.runtime.graph.Heads()
@ -160,7 +160,7 @@ func (srv *Server) Images(all, filter, quiet string) ([]ApiImages, error) {
continue
}
delete(allImages, id)
if quiet != "1" {
if !quiet {
out.Repository = name
out.Tag = tag
out.Id = TruncateId(id)
@ -175,7 +175,7 @@ func (srv *Server) Images(all, filter, quiet string) ([]ApiImages, error) {
if filter == "" {
for id, image := range allImages {
var out ApiImages
if quiet != "1" {
if !quiet {
out.Repository = "<none>"
out.Tag = "<none>"
out.Id = TruncateId(id)
@ -201,7 +201,7 @@ func (srv *Server) DockerInfo() ApiInfo {
out.Containers = len(srv.runtime.List())
out.Version = VERSION
out.Images = imgcount
if os.Getenv("DEBUG") == "1" {
if os.Getenv("DEBUG") != "" {
out.Debug = true
out.NFd = getTotalUsedFds()
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)
}
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'
for i, container := range srv.runtime.List() {
if !container.State.Running && all != "1" && n == -1 {
if !container.State.Running && !all && n == -1 {
continue
}
if i == n {
@ -264,9 +264,9 @@ func (srv *Server) Containers(all, notrunc, quiet string, n int) []ApiContainers
}
var out ApiContainers
out.Id = container.ShortId()
if quiet != "1" {
if !quiet {
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
if notrunc != "1" {
if !notrunc {
command = Trunc(command, 20)
}
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)
}
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 {
//logs
if logs == "1" {
if stdout == "1" {
if logs {
if stdout {
cLog, err := container.ReadLog("stdout")
if err != nil {
Debugf(err.Error())
@ -508,7 +508,7 @@ func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr str
Debugf(err.Error())
}
}
if stderr == "1" {
if stderr {
cLog, err := container.ReadLog("stderr")
if err != nil {
Debugf(err.Error())
@ -519,7 +519,7 @@ func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr str
}
//stream
if stream == "1" {
if stream {
if container.State.Ghost {
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
)
if stdin == "1" {
if stdin {
r, w := io.Pipe()
go func() {
defer w.Close()
@ -540,10 +540,10 @@ func (srv *Server) ContainerAttach(name, logs, stream, stdin, stdout, stderr str
cStdin = r
cStdinCloser = file
}
if stdout == "1" {
if stdout {
cStdout = file
}
if stderr == "1" {
if stderr {
cStderr = file
}