本文整理匯總了Golang中k8s/io/kubernetes/pkg/util/term.TTY.IsTerminal方法的典型用法代碼示例。如果您正苦於以下問題:Golang TTY.IsTerminal方法的具體用法?Golang TTY.IsTerminal怎麽用?Golang TTY.IsTerminal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/util/term.TTY
的用法示例。
在下文中一共展示了TTY.IsTerminal方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
// Run executes a validated remote execution against a pod.
func (p *AttachOptions) Run() error {
if p.Pod == nil {
pod, err := p.Client.Pods(p.Namespace).Get(p.PodName)
if err != nil {
return err
}
if pod.Status.Phase != api.PodRunning {
return fmt.Errorf("pod %s is not running and cannot be attached to; current phase is %s", p.PodName, pod.Status.Phase)
}
p.Pod = pod
// TODO: convert this to a clean "wait" behavior
}
pod := p.Pod
// ensure we can recover the terminal while attached
t := term.TTY{Parent: p.InterruptParent}
// check for TTY
tty := p.TTY
containerToAttach := p.GetContainer(pod)
if tty && !containerToAttach.TTY {
tty = false
fmt.Fprintf(p.Err, "Unable to use a TTY - container %s did not allocate one\n", containerToAttach.Name)
}
if p.Stdin {
t.In = p.In
if tty && !t.IsTerminal() {
tty = false
fmt.Fprintln(p.Err, "Unable to use a TTY - input is not a terminal or the right kind of file")
}
}
t.Raw = tty
fn := func() error {
if tty {
fmt.Fprintln(p.Out, "\nHit enter for command prompt")
}
// TODO: consider abstracting into a client invocation or client helper
req := p.Client.RESTClient.Post().
Resource("pods").
Name(pod.Name).
Namespace(pod.Namespace).
SubResource("attach")
req.VersionedParams(&api.PodAttachOptions{
Container: containerToAttach.Name,
Stdin: p.In != nil,
Stdout: p.Out != nil,
Stderr: p.Err != nil,
TTY: tty,
}, api.ParameterCodec)
return p.Attach.Attach("POST", req.URL(), p.Config, p.In, p.Out, p.Err, tty)
}
if err := t.Safe(fn); err != nil {
return err
}
if p.Stdin && tty && pod.Spec.RestartPolicy == api.RestartPolicyAlways {
fmt.Fprintf(p.Out, "Session ended, resume using '%s %s -c %s -i -t' command when the pod is running\n", p.CommandName, pod.Name, containerToAttach.Name)
}
return nil
}