mirror of https://github.com/docker/cli.git
Cleanup from CR.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
91dd0c0c69
commit
ef9ad85429
32
daemon.go
32
daemon.go
|
@ -1,11 +1,5 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const daemonBinary = "dockerd"
|
||||
|
||||
// DaemonProxy acts as a cli.Handler to proxy calls to the daemon binary
|
||||
|
@ -15,29 +9,3 @@ type DaemonProxy struct{}
|
|||
func NewDaemonProxy() DaemonProxy {
|
||||
return DaemonProxy{}
|
||||
}
|
||||
|
||||
// CmdDaemon execs dockerd with the same flags
|
||||
// TODO: add a deprecation warning?
|
||||
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
||||
args = stripDaemonArg(os.Args[1:])
|
||||
|
||||
binaryAbsPath, err := exec.LookPath(daemonBinary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return syscall.Exec(
|
||||
binaryAbsPath,
|
||||
append([]string{daemonBinary}, args...),
|
||||
os.Environ())
|
||||
}
|
||||
|
||||
// stripDaemonArg removes the `daemon` argument from the list
|
||||
func stripDaemonArg(args []string) []string {
|
||||
for i, arg := range args {
|
||||
if arg == "daemon" {
|
||||
return append(args[:i], args[i+1:]...)
|
||||
}
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// CmdDaemon execs dockerd with the same flags
|
||||
// TODO: add a deprecation warning?
|
||||
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
||||
// Use os.Args[1:] so that "global" args are passed to dockerd
|
||||
args = stripDaemonArg(os.Args[1:])
|
||||
|
||||
// TODO: check dirname args[0] first
|
||||
binaryAbsPath, err := exec.LookPath(daemonBinary)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return syscall.Exec(
|
||||
binaryAbsPath,
|
||||
append([]string{daemonBinary}, args...),
|
||||
os.Environ())
|
||||
}
|
||||
|
||||
// stripDaemonArg removes the `daemon` argument from the list
|
||||
func stripDaemonArg(args []string) []string {
|
||||
for i, arg := range args {
|
||||
if arg == "daemon" {
|
||||
return append(args[:i], args[i+1:]...)
|
||||
}
|
||||
}
|
||||
return args
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// CmdDaemon reports on an error on windows, because there is no exec
|
||||
func (p DaemonProxy) CmdDaemon(args ...string) error {
|
||||
return fmt.Errorf(
|
||||
"`docker daemon` does not exist on windows. Please run `dockerd` directly")
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCmdDaemon(t *testing.T) {
|
||||
proxy := NewDaemonProxy()
|
||||
err := proxy.CmdDaemon("--help")
|
||||
if err == nil {
|
||||
t.Fatal("Expected CmdDaemon to fail in Windows.")
|
||||
}
|
||||
|
||||
if !strings.Contains(err.Error(), "Please run `dockerd`") {
|
||||
t.Fatalf("Expected an error about running dockerd, got %s", err)
|
||||
}
|
||||
}
|
|
@ -9,16 +9,11 @@ import (
|
|||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if reexec.Init() {
|
||||
return
|
||||
}
|
||||
|
||||
// Set terminal emulation based on platform as required.
|
||||
stdin, stdout, stderr := term.StdStreams()
|
||||
|
||||
|
|
Loading…
Reference in New Issue