mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-03 15:28:35 +00:00
Refactor utils/utils, fixes #11923
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user