mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Re-enabled help for run command and added client-side error messages when arguments are missing
This commit is contained in:
parent
3cce89d8ed
commit
2333be46aa
2 changed files with 10 additions and 5 deletions
|
@ -814,14 +814,16 @@ func (srv *Server) CmdTag(stdin io.ReadCloser, stdout io.Writer, args ...string)
|
|||
}
|
||||
|
||||
func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||
config, err := ParseRun(args)
|
||||
config, err := ParseRun(args, stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if config.Image == "" {
|
||||
fmt.Fprintln(stdout, "Error: Image not specified")
|
||||
return fmt.Errorf("Image not specified")
|
||||
}
|
||||
if len(config.Cmd) == 0 {
|
||||
fmt.Fprintln(stdout, "Error: Command not specified")
|
||||
return fmt.Errorf("Command not specified")
|
||||
}
|
||||
// Create new container
|
||||
|
|
11
container.go
11
container.go
|
@ -3,8 +3,8 @@ package docker
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/rcli"
|
||||
"github.com/kr/pty"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -60,9 +60,12 @@ type Config struct {
|
|||
Image string // Name of the image as it was passed by the operator (eg. could be symbolic)
|
||||
}
|
||||
|
||||
func ParseRun(args []string) (*Config, error) {
|
||||
cmd := flag.NewFlagSet("", flag.ContinueOnError)
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||
cmd := rcli.Subcmd(stdout, "run", "[OPTIONS] IMAGE COMMAND [ARG...]", "Run a command in a new container")
|
||||
if len(args) > 0 && args[0] != "--help" {
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
}
|
||||
|
||||
fl_user := cmd.String("u", "", "Username or UID")
|
||||
fl_detach := 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")
|
||||
|
|
Loading…
Add table
Reference in a new issue