mirror of https://github.com/docker/docs.git
Merge remote-tracking branch 'titanous/camelize'
This commit is contained in:
commit
12a65dc4a8
|
@ -76,13 +76,13 @@ func LoadConfig(rootPath string) (*AuthConfig, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
arr := strings.Split(string(b), "\n")
|
arr := strings.Split(string(b), "\n")
|
||||||
orig_auth := strings.Split(arr[0], " = ")
|
origAuth := strings.Split(arr[0], " = ")
|
||||||
orig_email := strings.Split(arr[1], " = ")
|
origEmail := strings.Split(arr[1], " = ")
|
||||||
authConfig, err := DecodeAuth(orig_auth[1])
|
authConfig, err := DecodeAuth(origAuth[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
authConfig.Email = orig_email[1]
|
authConfig.Email = origEmail[1]
|
||||||
authConfig.rootPath = rootPath
|
authConfig.rootPath = rootPath
|
||||||
return authConfig, nil
|
return authConfig, nil
|
||||||
}
|
}
|
||||||
|
|
78
commands.go
78
commands.go
|
@ -493,7 +493,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
cmd := rcli.Subcmd(stdout, "images", "[OPTIONS] [NAME]", "List images")
|
cmd := rcli.Subcmd(stdout, "images", "[OPTIONS] [NAME]", "List images")
|
||||||
//limit := cmd.Int("l", 0, "Only show the N most recent versions of each image")
|
//limit := cmd.Int("l", 0, "Only show the N most recent versions of each image")
|
||||||
quiet := cmd.Bool("q", false, "only show numeric IDs")
|
quiet := cmd.Bool("q", false, "only show numeric IDs")
|
||||||
fl_a := cmd.Bool("a", false, "show all images")
|
flAll := cmd.Bool("a", false, "show all images")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
}
|
}
|
||||||
var allImages map[string]*Image
|
var allImages map[string]*Image
|
||||||
var err error
|
var err error
|
||||||
if *fl_a {
|
if *flAll {
|
||||||
allImages, err = srv.runtime.graph.Map()
|
allImages, err = srv.runtime.graph.Map()
|
||||||
} else {
|
} else {
|
||||||
allImages, err = srv.runtime.graph.Heads()
|
allImages, err = srv.runtime.graph.Heads()
|
||||||
|
@ -583,8 +583,8 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
cmd := rcli.Subcmd(stdout,
|
cmd := rcli.Subcmd(stdout,
|
||||||
"ps", "[OPTIONS]", "List containers")
|
"ps", "[OPTIONS]", "List containers")
|
||||||
quiet := cmd.Bool("q", false, "Only display numeric IDs")
|
quiet := cmd.Bool("q", false, "Only display numeric IDs")
|
||||||
fl_all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
|
flAll := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
|
||||||
fl_full := cmd.Bool("notrunc", false, "Don't truncate output")
|
flFull := cmd.Bool("notrunc", false, "Don't truncate output")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -593,12 +593,12 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tCOMMENT\n")
|
fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tCOMMENT\n")
|
||||||
}
|
}
|
||||||
for _, container := range srv.runtime.List() {
|
for _, container := range srv.runtime.List() {
|
||||||
if !container.State.Running && !*fl_all {
|
if !container.State.Running && !*flAll {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !*quiet {
|
if !*quiet {
|
||||||
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
command := fmt.Sprintf("%s %s", container.Path, strings.Join(container.Args, " "))
|
||||||
if !*fl_full {
|
if !*flFull {
|
||||||
command = Trunc(command, 20)
|
command = Trunc(command, 20)
|
||||||
}
|
}
|
||||||
for idx, field := range []string{
|
for idx, field := range []string{
|
||||||
|
@ -630,7 +630,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
cmd := rcli.Subcmd(stdout,
|
cmd := rcli.Subcmd(stdout,
|
||||||
"commit", "[OPTIONS] CONTAINER [REPOSITORY [TAG]]",
|
"commit", "[OPTIONS] CONTAINER [REPOSITORY [TAG]]",
|
||||||
"Create a new image from a container's changes")
|
"Create a new image from a container's changes")
|
||||||
fl_comment := cmd.String("m", "", "Commit message")
|
flComment := cmd.String("m", "", "Commit message")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -639,7 +639,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
img, err := srv.runtime.Commit(containerName, repository, tag, *fl_comment)
|
img, err := srv.runtime.Commit(containerName, repository, tag, *flComment)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -704,20 +704,20 @@ func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout io.Writer, args ...string
|
||||||
}
|
}
|
||||||
name := cmd.Arg(0)
|
name := cmd.Arg(0)
|
||||||
if container := srv.runtime.Get(name); container != nil {
|
if container := srv.runtime.Get(name); container != nil {
|
||||||
log_stdout, err := container.ReadLog("stdout")
|
logStdout, err := container.ReadLog("stdout")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log_stderr, err := container.ReadLog("stderr")
|
logStderr, err := container.ReadLog("stderr")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// FIXME: Interpolate stdout and stderr instead of concatenating them
|
// FIXME: Interpolate stdout and stderr instead of concatenating them
|
||||||
// FIXME: Differentiate stdout and stderr in the remote protocol
|
// FIXME: Differentiate stdout and stderr in the remote protocol
|
||||||
if _, err := io.Copy(stdout, log_stdout); err != nil {
|
if _, err := io.Copy(stdout, logStdout); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := io.Copy(stdout, log_stderr); err != nil {
|
if _, err := io.Copy(stdout, logStderr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -727,9 +727,9 @@ func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout io.Writer, args ...string
|
||||||
|
|
||||||
func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||||
cmd := rcli.Subcmd(stdout, "attach", "[OPTIONS]", "Attach to a running container")
|
cmd := rcli.Subcmd(stdout, "attach", "[OPTIONS]", "Attach to a running container")
|
||||||
fl_i := cmd.Bool("i", false, "Attach to stdin")
|
flStdin := cmd.Bool("i", false, "Attach to stdin")
|
||||||
fl_o := cmd.Bool("o", true, "Attach to stdout")
|
flStdout := cmd.Bool("o", true, "Attach to stdout")
|
||||||
fl_e := cmd.Bool("e", true, "Attach to stderr")
|
flStderr := cmd.Bool("e", true, "Attach to stderr")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -743,29 +743,29 @@ func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout io.Writer, args ...stri
|
||||||
return errors.New("No such container: " + name)
|
return errors.New("No such container: " + name)
|
||||||
}
|
}
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
if *fl_i {
|
if *flStdin {
|
||||||
c_stdin, err := container.StdinPipe()
|
cStdin, err := container.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() { io.Copy(c_stdin, stdin); wg.Add(-1) }()
|
go func() { io.Copy(cStdin, stdin); wg.Add(-1) }()
|
||||||
}
|
}
|
||||||
if *fl_o {
|
if *flStdout {
|
||||||
c_stdout, err := container.StdoutPipe()
|
cStdout, err := container.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() { io.Copy(stdout, c_stdout); wg.Add(-1) }()
|
go func() { io.Copy(stdout, cStdout); wg.Add(-1) }()
|
||||||
}
|
}
|
||||||
if *fl_e {
|
if *flStderr {
|
||||||
c_stderr, err := container.StderrPipe()
|
cStderr, err := container.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() { io.Copy(stdout, c_stderr); wg.Add(-1) }()
|
go func() { io.Copy(stdout, cStderr); wg.Add(-1) }()
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return nil
|
return nil
|
||||||
|
@ -843,46 +843,46 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.OpenStdin {
|
if config.OpenStdin {
|
||||||
cmd_stdin, err := container.StdinPipe()
|
cmdStdin, err := container.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !config.Detach {
|
if !config.Detach {
|
||||||
Go(func() error {
|
Go(func() error {
|
||||||
_, err := io.Copy(cmd_stdin, stdin)
|
_, err := io.Copy(cmdStdin, stdin)
|
||||||
cmd_stdin.Close()
|
cmdStdin.Close()
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Run the container
|
// Run the container
|
||||||
if !config.Detach {
|
if !config.Detach {
|
||||||
cmd_stderr, err := container.StderrPipe()
|
cmdStderr, err := container.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cmd_stdout, err := container.StdoutPipe()
|
cmdStdout, err := container.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sending_stdout := Go(func() error {
|
sendingStdout := Go(func() error {
|
||||||
_, err := io.Copy(stdout, cmd_stdout)
|
_, err := io.Copy(stdout, cmdStdout)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
sending_stderr := Go(func() error {
|
sendingStderr := Go(func() error {
|
||||||
_, err := io.Copy(stdout, cmd_stderr)
|
_, err := io.Copy(stdout, cmdStderr)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
err_sending_stdout := <-sending_stdout
|
errSendingStdout := <-sendingStdout
|
||||||
err_sending_stderr := <-sending_stderr
|
errSendingStderr := <-sendingStderr
|
||||||
if err_sending_stdout != nil {
|
if errSendingStdout != nil {
|
||||||
return err_sending_stdout
|
return errSendingStdout
|
||||||
}
|
}
|
||||||
if err_sending_stderr != nil {
|
if errSendingStderr != nil {
|
||||||
return err_sending_stderr
|
return errSendingStderr
|
||||||
}
|
}
|
||||||
container.Wait()
|
container.Wait()
|
||||||
} else {
|
} else {
|
||||||
|
|
60
container.go
60
container.go
|
@ -66,16 +66,16 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||||
cmd.SetOutput(ioutil.Discard)
|
cmd.SetOutput(ioutil.Discard)
|
||||||
}
|
}
|
||||||
|
|
||||||
fl_user := cmd.String("u", "", "Username or UID")
|
flUser := cmd.String("u", "", "Username or UID")
|
||||||
fl_detach := cmd.Bool("d", false, "Detached mode: leave the container running in the background")
|
flDetach := cmd.Bool("d", false, "Detached mode: leave the container running in the background")
|
||||||
fl_stdin := cmd.Bool("i", false, "Keep stdin open even if not attached")
|
flStdin := cmd.Bool("i", false, "Keep stdin open even if not attached")
|
||||||
fl_tty := cmd.Bool("t", false, "Allocate a pseudo-tty")
|
flTty := cmd.Bool("t", false, "Allocate a pseudo-tty")
|
||||||
fl_memory := cmd.Int64("m", 0, "Memory limit (in bytes)")
|
flMemory := cmd.Int64("m", 0, "Memory limit (in bytes)")
|
||||||
var fl_ports ports
|
var flPorts ports
|
||||||
|
|
||||||
cmd.Var(&fl_ports, "p", "Map a network port to the container")
|
cmd.Var(&flPorts, "p", "Map a network port to the container")
|
||||||
var fl_env ListOpts
|
var flEnv ListOpts
|
||||||
cmd.Var(&fl_env, "e", "Set environment variables")
|
cmd.Var(&flEnv, "e", "Set environment variables")
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -89,13 +89,13 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||||
runCmd = parsedArgs[1:]
|
runCmd = parsedArgs[1:]
|
||||||
}
|
}
|
||||||
config := &Config{
|
config := &Config{
|
||||||
Ports: fl_ports,
|
Ports: flPorts,
|
||||||
User: *fl_user,
|
User: *flUser,
|
||||||
Tty: *fl_tty,
|
Tty: *flTty,
|
||||||
OpenStdin: *fl_stdin,
|
OpenStdin: *flStdin,
|
||||||
Memory: *fl_memory,
|
Memory: *flMemory,
|
||||||
Detach: *fl_detach,
|
Detach: *flDetach,
|
||||||
Env: fl_env,
|
Env: flEnv,
|
||||||
Cmd: runCmd,
|
Cmd: runCmd,
|
||||||
Image: image,
|
Image: image,
|
||||||
}
|
}
|
||||||
|
@ -150,52 +150,52 @@ func (container *Container) generateLXCConfig() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) startPty() error {
|
func (container *Container) startPty() error {
|
||||||
stdout_master, stdout_slave, err := pty.Open()
|
stdoutMaster, stdoutSlave, err := pty.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
container.cmd.Stdout = stdout_slave
|
container.cmd.Stdout = stdoutSlave
|
||||||
|
|
||||||
stderr_master, stderr_slave, err := pty.Open()
|
stderrMaster, stderrSlave, err := pty.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
container.cmd.Stderr = stderr_slave
|
container.cmd.Stderr = stderrSlave
|
||||||
|
|
||||||
// Copy the PTYs to our broadcasters
|
// Copy the PTYs to our broadcasters
|
||||||
go func() {
|
go func() {
|
||||||
defer container.stdout.Close()
|
defer container.stdout.Close()
|
||||||
io.Copy(container.stdout, stdout_master)
|
io.Copy(container.stdout, stdoutMaster)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer container.stderr.Close()
|
defer container.stderr.Close()
|
||||||
io.Copy(container.stderr, stderr_master)
|
io.Copy(container.stderr, stderrMaster)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// stdin
|
// stdin
|
||||||
var stdin_slave io.ReadCloser
|
var stdinSlave io.ReadCloser
|
||||||
if container.Config.OpenStdin {
|
if container.Config.OpenStdin {
|
||||||
stdin_master, stdin_slave, err := pty.Open()
|
stdinMaster, stdinSlave, err := pty.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
container.cmd.Stdin = stdin_slave
|
container.cmd.Stdin = stdinSlave
|
||||||
// FIXME: The following appears to be broken.
|
// FIXME: The following appears to be broken.
|
||||||
// "cannot set terminal process group (-1): Inappropriate ioctl for device"
|
// "cannot set terminal process group (-1): Inappropriate ioctl for device"
|
||||||
// container.cmd.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true}
|
// container.cmd.SysProcAttr = &syscall.SysProcAttr{Setctty: true, Setsid: true}
|
||||||
go func() {
|
go func() {
|
||||||
defer container.stdin.Close()
|
defer container.stdin.Close()
|
||||||
io.Copy(stdin_master, container.stdin)
|
io.Copy(stdinMaster, container.stdin)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if err := container.cmd.Start(); err != nil {
|
if err := container.cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stdout_slave.Close()
|
stdoutSlave.Close()
|
||||||
stderr_slave.Close()
|
stderrSlave.Close()
|
||||||
if stdin_slave != nil {
|
if stdinSlave != nil {
|
||||||
stdin_slave.Close()
|
stdinSlave.Close()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,11 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// FIXME: Switch d and D ? (to be more sshd like)
|
// FIXME: Switch d and D ? (to be more sshd like)
|
||||||
fl_daemon := flag.Bool("d", false, "Daemon mode")
|
flDaemon := flag.Bool("d", false, "Daemon mode")
|
||||||
fl_debug := flag.Bool("D", false, "Debug mode")
|
flDebug := flag.Bool("D", false, "Debug mode")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
rcli.DEBUG_FLAG = *fl_debug
|
rcli.DEBUG_FLAG = *flDebug
|
||||||
if *fl_daemon {
|
if *flDaemon {
|
||||||
if flag.NArg() != 0 {
|
if flag.NArg() != 0 {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
return
|
return
|
||||||
|
@ -59,22 +59,22 @@ func runCommand(args []string) error {
|
||||||
// closing the connection.
|
// closing the connection.
|
||||||
// See http://code.google.com/p/go/issues/detail?id=3345
|
// See http://code.google.com/p/go/issues/detail?id=3345
|
||||||
if conn, err := rcli.Call("tcp", "127.0.0.1:4242", args...); err == nil {
|
if conn, err := rcli.Call("tcp", "127.0.0.1:4242", args...); err == nil {
|
||||||
receive_stdout := docker.Go(func() error {
|
receiveStdout := docker.Go(func() error {
|
||||||
_, err := io.Copy(os.Stdout, conn)
|
_, err := io.Copy(os.Stdout, conn)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
send_stdin := docker.Go(func() error {
|
sendStdin := docker.Go(func() error {
|
||||||
_, err := io.Copy(conn, os.Stdin)
|
_, err := io.Copy(conn, os.Stdin)
|
||||||
if err := conn.CloseWrite(); err != nil {
|
if err := conn.CloseWrite(); err != nil {
|
||||||
log.Printf("Couldn't send EOF: " + err.Error())
|
log.Printf("Couldn't send EOF: " + err.Error())
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if err := <-receive_stdout; err != nil {
|
if err := <-receiveStdout; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !term.IsTerminal(0) {
|
if !term.IsTerminal(0) {
|
||||||
if err := <-send_stdin; err != nil {
|
if err := <-sendStdin; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,9 +234,9 @@ func NewRuntime() (*Runtime, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRuntimeFromDirectory(root string) (*Runtime, error) {
|
func NewRuntimeFromDirectory(root string) (*Runtime, error) {
|
||||||
runtime_repo := path.Join(root, "containers")
|
runtimeRepo := path.Join(root, "containers")
|
||||||
|
|
||||||
if err := os.MkdirAll(runtime_repo, 0700); err != nil && !os.IsExist(err) {
|
if err := os.MkdirAll(runtimeRepo, 0700); err != nil && !os.IsExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ func NewRuntimeFromDirectory(root string) (*Runtime, error) {
|
||||||
|
|
||||||
runtime := &Runtime{
|
runtime := &Runtime{
|
||||||
root: root,
|
root: root,
|
||||||
repository: runtime_repo,
|
repository: runtimeRepo,
|
||||||
containers: list.New(),
|
containers: list.New(),
|
||||||
networkManager: netManager,
|
networkManager: netManager,
|
||||||
graph: g,
|
graph: g,
|
||||||
|
|
24
utils.go
24
utils.go
|
@ -63,25 +63,25 @@ func Debugf(format string, a ...interface{}) {
|
||||||
|
|
||||||
// Reader with progress bar
|
// Reader with progress bar
|
||||||
type progressReader struct {
|
type progressReader struct {
|
||||||
reader io.ReadCloser // Stream to read from
|
reader io.ReadCloser // Stream to read from
|
||||||
output io.Writer // Where to send progress bar to
|
output io.Writer // Where to send progress bar to
|
||||||
read_total int // Expected stream length (bytes)
|
readTotal int // Expected stream length (bytes)
|
||||||
read_progress int // How much has been read so far (bytes)
|
readProgress int // How much has been read so far (bytes)
|
||||||
last_update int // How many bytes read at least update
|
lastUpdate int // How many bytes read at least update
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *progressReader) Read(p []byte) (n int, err error) {
|
func (r *progressReader) Read(p []byte) (n int, err error) {
|
||||||
read, err := io.ReadCloser(r.reader).Read(p)
|
read, err := io.ReadCloser(r.reader).Read(p)
|
||||||
r.read_progress += read
|
r.readProgress += read
|
||||||
|
|
||||||
// Only update progress for every 1% read
|
// Only update progress for every 1% read
|
||||||
update_every := int(0.01 * float64(r.read_total))
|
updateEvery := int(0.01 * float64(r.readTotal))
|
||||||
if r.read_progress-r.last_update > update_every || r.read_progress == r.read_total {
|
if r.readProgress-r.lastUpdate > updateEvery || r.readProgress == r.readTotal {
|
||||||
fmt.Fprintf(r.output, "%d/%d (%.0f%%)\r",
|
fmt.Fprintf(r.output, "%d/%d (%.0f%%)\r",
|
||||||
r.read_progress,
|
r.readProgress,
|
||||||
r.read_total,
|
r.readTotal,
|
||||||
float64(r.read_progress)/float64(r.read_total)*100)
|
float64(r.readProgress)/float64(r.readTotal)*100)
|
||||||
r.last_update = r.read_progress
|
r.lastUpdate = r.readProgress
|
||||||
}
|
}
|
||||||
// Send newline when complete
|
// Send newline when complete
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
|
|
Loading…
Reference in New Issue