Refactor utils/utils, fixes #11923

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
Antonio Murdaca
2015-04-14 01:37:36 +02:00
parent 7ecf4e5d4d
commit c30a55f14d
46 changed files with 530 additions and 427 deletions
+1 -2
View File
@@ -9,7 +9,6 @@ import (
"github.com/docker/docker/engine"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/utils"
)
// CmdAttach attaches to a running container.
@@ -81,7 +80,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
return err
}
if status != 0 {
return &utils.StatusError{StatusCode: status}
return &StatusError{StatusCode: status}
}
return nil
+1 -1
View File
@@ -302,7 +302,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
if jerr.Code == 0 {
jerr.Code = 1
}
return &utils.StatusError{Status: jerr.Message, StatusCode: jerr.Code}
return &StatusError{Status: jerr.Message, StatusCode: jerr.Code}
}
return err
}
+12
View File
@@ -3,3 +3,15 @@
// Run "docker help SUBCOMMAND" or "docker SUBCOMMAND --help" to see more information on any Docker subcommand, including the full list of options supported for the subcommand.
// See https://docs.docker.com/installation/ for instructions on installing Docker.
package client
import "fmt"
// An StatusError reports an unsuccessful exit by a command.
type StatusError struct {
Status string
StatusCode int
}
func (e *StatusError) Error() string {
return fmt.Sprintf("Status: %s, Code: %d", e.Status, e.StatusCode)
}
+2 -3
View File
@@ -9,7 +9,6 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
)
// CmdExec runs a command in a running container.
@@ -21,7 +20,7 @@ func (cli *DockerCli) CmdExec(args ...string) error {
execConfig, err := runconfig.ParseExec(cmd, args)
// just in case the ParseExec does not exit
if execConfig.Container == "" || err != nil {
return &utils.StatusError{StatusCode: 1}
return &StatusError{StatusCode: 1}
}
stream, _, err := cli.call("POST", "/containers/"+execConfig.Container+"/exec", execConfig, nil)
@@ -122,7 +121,7 @@ func (cli *DockerCli) CmdExec(args ...string) error {
}
if status != 0 {
return &utils.StatusError{StatusCode: status}
return &StatusError{StatusCode: status}
}
return nil
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"github.com/docker/docker/api/types"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/stringutils"
"github.com/docker/docker/pkg/units"
"github.com/docker/docker/utils"
)
// CmdHistory shows the history of an image.
@@ -51,7 +51,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
if *noTrunc {
fmt.Fprintf(w, "%s\t", entry.CreatedBy)
} else {
fmt.Fprintf(w, "%s\t", utils.Trunc(entry.CreatedBy, 45))
fmt.Fprintf(w, "%s\t", stringutils.Truncate(entry.CreatedBy, 45))
}
fmt.Fprintf(w, "%s\t", units.HumanSize(float64(entry.Size)))
fmt.Fprintf(w, "%s", entry.Comment)
+2 -3
View File
@@ -9,7 +9,6 @@ import (
"text/template"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/utils"
)
// CmdInspect displays low-level information on one or more containers or images.
@@ -27,7 +26,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
var err error
if tmpl, err = template.New("").Funcs(funcMap).Parse(*tmplStr); err != nil {
fmt.Fprintf(cli.err, "Template parsing error: %v\n", err)
return &utils.StatusError{StatusCode: 64,
return &StatusError{StatusCode: 64,
Status: "Template parsing error: " + err.Error()}
}
}
@@ -86,7 +85,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
}
if status != 0 {
return &utils.StatusError{StatusCode: status}
return &StatusError{StatusCode: status}
}
return nil
}
+2 -2
View File
@@ -15,8 +15,8 @@ import (
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers/filters"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/stringutils"
"github.com/docker/docker/pkg/units"
"github.com/docker/docker/utils"
)
// CmdPs outputs a list of Docker containers.
@@ -135,7 +135,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
)
if !*noTrunc {
command = utils.Trunc(command, 20)
command = stringutils.Truncate(command, 20)
// only display the default name for the container with notrunc is passed
for _, name := range names {
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"github.com/docker/docker/pkg/resolvconf"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
)
func (cid *cidFile) Close() error {
@@ -242,7 +241,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
}
}
if status != 0 {
return &utils.StatusError{StatusCode: status}
return &StatusError{StatusCode: status}
}
return nil
}
+2 -2
View File
@@ -10,8 +10,8 @@ import (
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/stringutils"
"github.com/docker/docker/registry"
"github.com/docker/docker/utils"
)
type ByStars []registry.SearchResult
@@ -68,7 +68,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
desc := strings.Replace(res.Description, "\n", " ", -1)
desc = strings.Replace(desc, "\r", " ", -1)
if !*noTrunc && len(desc) > 45 {
desc = utils.Trunc(desc, 42) + "..."
desc = stringutils.Truncate(desc, 42) + "..."
}
fmt.Fprintf(w, "%s\t%s\t%d\t", res.Name, desc, res.StarCount)
if res.IsOfficial {
+1 -2
View File
@@ -11,7 +11,6 @@ import (
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/utils"
)
func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal {
@@ -156,7 +155,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
return err
}
if status != 0 {
return &utils.StatusError{StatusCode: status}
return &StatusError{StatusCode: status}
}
}
return nil