mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Removed interactive mode ('docker -i'). Cool UI experiment but seems more trouble than it's worth
This commit is contained in:
parent
150a4fe7e5
commit
d2cba75d5f
2 changed files with 2 additions and 91 deletions
|
@ -4,12 +4,8 @@ import (
|
|||
"../future"
|
||||
"../rcli"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Run docker in "simple mode": run a single command and return.
|
||||
|
@ -55,72 +51,3 @@ func SimpleMode(args []string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run docker in "interactive mode": run a bash-compatible shell capable of running docker commands.
|
||||
func InteractiveMode(scripts ...string) error {
|
||||
// Determine path of current docker binary
|
||||
dockerPath, err := exec.LookPath(os.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dockerPath, err = filepath.Abs(dockerPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a temp directory
|
||||
tmp, err := ioutil.TempDir("", "docker-shell")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
// For each command, create an alias in temp directory
|
||||
// FIXME: generate this list dynamically with introspection of some sort
|
||||
// It might make sense to merge docker and dockerd to keep that introspection
|
||||
// within a single binary.
|
||||
for _, cmd := range []string{
|
||||
"help",
|
||||
"run",
|
||||
"ps",
|
||||
"pull",
|
||||
"put",
|
||||
"rm",
|
||||
"kill",
|
||||
"wait",
|
||||
"stop",
|
||||
"start",
|
||||
"restart",
|
||||
"logs",
|
||||
"diff",
|
||||
"commit",
|
||||
"attach",
|
||||
"info",
|
||||
"tar",
|
||||
"web",
|
||||
"images",
|
||||
"docker",
|
||||
} {
|
||||
if err := os.Symlink(dockerPath, path.Join(tmp, cmd)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Run $SHELL with PATH set to temp directory
|
||||
rcfile, err := ioutil.TempFile("", "docker-shell-rc")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(rcfile.Name())
|
||||
io.WriteString(rcfile, "enable -n help\n")
|
||||
os.Setenv("PATH", tmp+":"+os.Getenv("PATH"))
|
||||
os.Setenv("PS1", "\\h docker> ")
|
||||
shell := exec.Command("/bin/bash", append([]string{"--rcfile", rcfile.Name()}, scripts...)...)
|
||||
shell.Stdin = os.Stdin
|
||||
shell.Stdout = os.Stdout
|
||||
shell.Stderr = os.Stderr
|
||||
if err := shell.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,28 +2,12 @@ package main
|
|||
|
||||
import (
|
||||
"../client"
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if cmd := path.Base(os.Args[0]); cmd == "docker" {
|
||||
fl_shell := flag.Bool("i", false, "Interactive mode")
|
||||
flag.Parse()
|
||||
if *fl_shell {
|
||||
if err := client.InteractiveMode(flag.Args()...); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if err := client.SimpleMode(os.Args[1:]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err := client.SimpleMode(append([]string{cmd}, os.Args[1:]...)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := client.SimpleMode(os.Args[1:]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue