本文整理匯總了Golang中github.com/docker/docker/pkg/term.StdStreams函數的典型用法代碼示例。如果您正苦於以下問題:Golang StdStreams函數的具體用法?Golang StdStreams怎麽用?Golang StdStreams使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了StdStreams函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Exec
// Exec
func Exec(params string) error {
// connect to the server; this will wait until a single read is returned from
// the server (blocking)
conn, data, err := connect(fmt.Sprintf("POST /exec?pid=%d&%v HTTP/1.1\r\n\r\n", os.Getpid(), params))
if err != nil {
return err
}
defer conn.Close()
// begin watching for changes to the project
go func() {
if err := notifyutil.Watch(config.CWDir, NotifyServer); err != nil {
fmt.Printf(err.Error())
}
}()
// get current term info
stdIn, stdOut, _ := term.StdStreams()
//
terminal.Connect(stdIn, stdOut)
// print the first read data from above
os.Stderr.WriteString(string(data))
//
return pipeToConnection(conn, stdIn, stdOut)
}
示例2: main
func main() {
if reexec.Init() {
return
}
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()
logrus.SetOutput(stderr)
flag.Merge(flag.CommandLine, clientFlags.FlagSet, commonFlags.FlagSet)
flag.Usage = func() {
fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n"+daemonUsage+" docker [ -h | --help | -v | --version ]\n\n")
fmt.Fprint(os.Stdout, "A self-sufficient runtime for containers.\n\nOptions:\n")
flag.CommandLine.SetOutput(os.Stdout)
flag.PrintDefaults()
help := "\nCommands:\n"
for _, cmd := range dockerCommands {
help += fmt.Sprintf(" %-10.10s%s\n", cmd.name, cmd.description)
}
help += "\nRun 'docker COMMAND --help' for more information on a command."
fmt.Fprintf(os.Stdout, "%s\n", help)
}
flag.Parse()
if *flVersion {
showVersion()
return
}
clientCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags)
// TODO: remove once `-d` is retired
handleGlobalDaemonFlag()
if *flHelp {
// if global flag --help is present, regardless of what other options and commands there are,
// just print the usage.
flag.Usage()
return
}
c := cli.New(clientCli, daemonCli)
if err := c.Run(flag.Args()...); err != nil {
if sterr, ok := err.(cli.StatusError); ok {
if sterr.Status != "" {
fmt.Fprintln(os.Stderr, sterr.Status)
os.Exit(1)
}
os.Exit(sterr.StatusCode)
}
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
示例3: Develop
// Develop
func Develop(params string, mist mistClient.Client) error {
// connect to the server; this will wait until a single read is returned from
// the server (blocking)
conn, data, err := connect(fmt.Sprintf("POST /develop?pid=%d&%v HTTP/1.1\r\n\r\n", os.Getpid(), params))
if err != nil {
return err
}
defer conn.Close()
// disconnect mist
mist.Close()
// begin watching for changes to the project
go func() {
if err := notifyutil.Watch(config.CWDir, NotifyServer); err != nil {
fmt.Printf(err.Error())
}
}()
//
os.Stderr.WriteString(fmt.Sprintf(`+> Opening a nanobox console:
**
********
***************
*********************
*****************
:: ********* ::
:: *** ::
++ ::: ::: ++
++ ::: ++
++ ++
+
_ _ ____ _ _ ____ ___ ____ _ _
|\ | |__| |\ | | | |__) | | \/
| \| | | | \| |__| |__) |__| _/\_
--------------------------------------------------------------------------------
+ You are in a virtual machine (vm)
+ Your local source code has been mounted into the vm, and changes in either
the vm or local will be mirrored.
+ If you run a server, access it at >> %s
--------------------------------------------------------------------------------
`, config.Nanofile.Domain))
// get current term info
stdIn, stdOut, _ := term.StdStreams()
//
terminal.Connect(stdIn, stdOut)
// print the first read data from above
os.Stderr.WriteString(string(data))
//
return pipeToConnection(conn, stdIn, stdOut)
}
示例4: Exec
// Exec
func Exec(where, params string) error {
//
stdIn, stdOut, _ := term.StdStreams()
//
return execInternal(where, params, stdIn, stdOut)
}
示例5: main
func main() {
_, stdout, stderr := term.StdStreams()
logrus.SetOutput(stderr)
err := dnetCommand(stdout, stderr)
if err != nil {
os.Exit(1)
}
}
示例6: NewCobraAdaptor
// NewCobraAdaptor returns a new handler
func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
stdin, stdout, stderr := term.StdStreams()
dockerCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags)
var rootCmd = &cobra.Command{
Use: "docker",
SilenceUsage: true,
SilenceErrors: true,
}
rootCmd.SetUsageTemplate(usageTemplate)
rootCmd.SetHelpTemplate(helpTemplate)
rootCmd.SetFlagErrorFunc(cli.FlagErrorFunc)
rootCmd.SetOutput(stdout)
rootCmd.AddCommand(
container.NewAttachCommand(dockerCli),
container.NewCreateCommand(dockerCli),
container.NewDiffCommand(dockerCli),
container.NewExportCommand(dockerCli),
container.NewKillCommand(dockerCli),
container.NewLogsCommand(dockerCli),
container.NewPauseCommand(dockerCli),
container.NewPortCommand(dockerCli),
container.NewRenameCommand(dockerCli),
container.NewRestartCommand(dockerCli),
container.NewRmCommand(dockerCli),
container.NewRunCommand(dockerCli),
container.NewStartCommand(dockerCli),
container.NewStatsCommand(dockerCli),
container.NewStopCommand(dockerCli),
container.NewTopCommand(dockerCli),
container.NewUnpauseCommand(dockerCli),
container.NewWaitCommand(dockerCli),
image.NewBuildCommand(dockerCli),
image.NewHistoryCommand(dockerCli),
image.NewImagesCommand(dockerCli),
image.NewLoadCommand(dockerCli),
image.NewRemoveCommand(dockerCli),
image.NewSaveCommand(dockerCli),
image.NewSearchCommand(dockerCli),
image.NewImportCommand(dockerCli),
image.NewTagCommand(dockerCli),
network.NewNetworkCommand(dockerCli),
system.NewEventsCommand(dockerCli),
system.NewVersionCommand(dockerCli),
volume.NewVolumeCommand(dockerCli),
)
rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
return CobraAdaptor{
rootCmd: rootCmd,
dockerCli: dockerCli,
}
}
示例7: newDockerClient
func newDockerClient() *client.DockerCli {
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()
setDefaultConfFlag(flTrustKey, defaultTrustKeyFile)
if len(flHosts) > 1 {
log.Fatal("Please specify only one -H")
}
protoAddrParts := strings.SplitN(flHosts[0], "://", 2)
var (
cli *client.DockerCli
tlsConfig tls.Config
)
tlsConfig.InsecureSkipVerify = true
// Regardless of whether the user sets it to true or false, if they
// specify --tlsverify at all then we need to turn on tls
if flag.IsSet("-tlsverify") {
*flTls = true
}
// If we should verify the server, we need to load a trusted ca
if *flTlsVerify {
certPool := x509.NewCertPool()
file, err := ioutil.ReadFile(*flCa)
if err != nil {
log.Fatalf("Couldn't read ca cert %s: %s", *flCa, err)
}
certPool.AppendCertsFromPEM(file)
tlsConfig.RootCAs = certPool
tlsConfig.InsecureSkipVerify = false
}
// If tls is enabled, try to load and send client certificates
if *flTls || *flTlsVerify {
_, errCert := os.Stat(*flCert)
_, errKey := os.Stat(*flKey)
if errCert == nil && errKey == nil {
*flTls = true
cert, err := tls.LoadX509KeyPair(*flCert, *flKey)
if err != nil {
log.Fatalf("Couldn't load X509 key pair: %q. Make sure the key is encrypted", err)
}
tlsConfig.Certificates = []tls.Certificate{cert}
}
// Avoid fallback to SSL protocols < TLS1.0
tlsConfig.MinVersion = tls.VersionTLS10
}
cli = client.NewDockerCli(stdin, stdout, stderr, *flTrustKey, protoAddrParts[0], protoAddrParts[1], &tlsConfig)
return cli
}
示例8: main
func main() {
if reexec.Init() {
return
}
// Set terminal emulation based on platform as required.
_, stdout, stderr := term.StdStreams()
logrus.SetOutput(stderr)
flag.Merge(flag.CommandLine, daemonCli.commonFlags.FlagSet)
flag.Usage = func() {
fmt.Fprint(stdout, "Usage: dockerd [ --help | -v | --version ]\n\n")
fmt.Fprint(stdout, "A self-sufficient runtime for containers.\n\nOptions:\n")
flag.CommandLine.SetOutput(stdout)
flag.PrintDefaults()
}
flag.CommandLine.ShortUsage = func() {
fmt.Fprint(stderr, "\nUsage:\tdockerd [OPTIONS]\n")
}
if err := flag.CommandLine.ParseFlags(os.Args[1:], false); err != nil {
os.Exit(1)
}
if *flVersion {
showVersion()
return
}
if *flHelp {
// if global flag --help is present, regardless of what other options and commands there are,
// just print the usage.
flag.Usage()
return
}
// On Windows, this may be launching as a service or with an option to
// register the service.
stop, err := initService()
if err != nil {
logrus.Fatal(err)
}
if !stop {
err = daemonCli.start()
notifyShutdown(err)
if err != nil {
logrus.Fatal(err)
}
}
}
示例9: Console
// Console
func Console(params string) error {
// connect to the server; this will wait until a single read is returned from
// the server (blocking)
conn, data, err := connect(fmt.Sprintf("POST /exec?pid=%d&%v HTTP/1.1\r\n\r\n", os.Getpid(), params))
if err != nil {
return err
}
defer conn.Close()
// begin watching for changes to the project
go func() {
if err := notifyutil.Watch(config.CWDir, NotifyServer); err != nil {
fmt.Printf(err.Error())
}
}()
//
os.Stderr.WriteString(`+> Opening a nanobox console:
**
********
***************
*********************
*****************
:: ********* ::
:: *** ::
++ ::: ::: ++
++ ::: ++
++ ++
+
_ _ ____ _ _ ____ ___ ____ _ _
|\ | |__| |\ | | | |__) | | \/
| \| | | | \| |__| |__) |__| _/\_
`)
// get current term info
stdIn, stdOut, _ := term.StdStreams()
// connect a raw terminal; if no error is returned defer resetting the terminal
state, err := terminal.Connect(stdIn, stdOut)
if err == nil {
defer terminal.Disconnect(stdIn, state)
}
// print the first read data from above
os.Stderr.Write(data)
//
return pipeToConnection(conn, stdIn, stdOut)
}
示例10: Console
// Console opens a secure console to a code or database service. For code
// services, a command is required. This command is executed as root in the
// context of the application root directory. For database services, no command
// is needed - instead, the appropriate command for the database type is run.
// For example, for a postgres database, psql is run.
func Console(serviceLabel string, command string, settings *models.Settings) {
helpers.SignIn(settings)
service := helpers.RetrieveServiceByLabel(serviceLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", serviceLabel)
os.Exit(1)
}
fmt.Printf("Opening console to %s (%s)\n", serviceLabel, service.ID)
task := helpers.RequestConsole(command, service.ID, settings)
fmt.Print("Waiting for the console to be ready. This might take a minute.")
ch := make(chan string, 1)
go helpers.PollConsoleJob(task.ID, service.ID, ch, settings)
jobID := <-ch
defer helpers.DestroyConsole(jobID, service.ID, settings)
creds := helpers.RetrieveConsoleTokens(jobID, service.ID, settings)
creds.URL = strings.Replace(creds.URL, "http", "ws", 1)
fmt.Println("Connecting...")
// BEGIN websocket impl
config, _ := websocket.NewConfig(creds.URL, "ws://localhost:9443/")
config.TlsConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
config.Header["X-Console-Token"] = []string{creds.Token}
ws, err := websocket.DialConfig(config)
if err != nil {
panic(err)
}
defer ws.Close()
fmt.Println("Connection opened")
stdin, stdout, _ := term.StdStreams()
fdIn, isTermIn := term.GetFdInfo(stdin)
if !isTermIn {
panic(errors.New("StdIn is not a terminal"))
}
oldState, err := term.SetRawTerminal(fdIn)
if err != nil {
panic(err)
}
done := make(chan bool)
msgCh := make(chan []byte, 2)
go webSocketDaemon(ws, &stdout, done, msgCh)
signal.Notify(make(chan os.Signal, 1), os.Interrupt)
defer term.RestoreTerminal(fdIn, oldState)
go termDaemon(&stdin, ws)
<-done
}
示例11: main
func main() {
if reexec.Init() {
return
}
_, stdout, stderr := term.StdStreams()
logrus.SetOutput(stderr)
err := dnetApp(stdout, stderr)
if err != nil {
os.Exit(1)
}
}
示例12: runDockerCommand
func runDockerCommand(c *cli.Context, cmd string) {
_, stdout, stderr := term.StdStreams()
oldcli := client.NewNetworkCli(stdout, stderr, epConn.httpCall)
var args []string
args = append(args, cmd)
if c.Bool("h") {
args = append(args, "--help")
} else {
args = append(args, c.Args()...)
}
if err := oldcli.Cmd("dnet", args...); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
示例13: promptForCredentials
func promptForCredentials(settings *models.Settings) {
var username string
fmt.Print("Username: ")
fmt.Scanln(&username)
settings.Username = username
fmt.Print("Password: ")
var fd uintptr
if runtime.GOOS == "windows" {
stdIn, _, _ := term.StdStreams()
fd, _ = term.GetFdInfo(stdIn)
}
bytes, _ := terminal.ReadPassword(int(fd))
fmt.Println("")
settings.Password = string(bytes)
}
示例14: main
func main() {
if reexec.Init() {
return
}
// Set terminal emulation based on platform as required.
_, stdout, stderr := term.StdStreams()
logrus.SetOutput(stderr)
cmd := newDaemonCommand()
cmd.SetOutput(stdout)
if err := cmd.Execute(); err != nil {
fmt.Fprintf(stderr, "%s\n", err)
os.Exit(1)
}
}
示例15: NewKubectlServer
func NewKubectlServer() *Server {
// need to use term.StdStreams to get the right IO refs on Windows
stdin, stdout, stderr := term.StdStreams()
cmd := cmd.NewKubectlCommand(cmdutil.NewFactory(nil), stdin, stdout, stderr)
localFlags := cmd.LocalFlags()
localFlags.SetInterspersed(false)
return &Server{
name: "kubectl",
SimpleUsage: "Kubernetes command line client",
Long: "Kubernetes command line client",
Run: func(s *Server, args []string) error {
cmd.SetArgs(args)
return cmd.Execute()
},
flags: localFlags,
}
}