Skip to content

Commit 1e3869d

Browse files
authored
Merge pull request #324 from covexo/fixes
Fixes
2 parents e1941a9 + 1a877d2 commit 1e3869d

4 files changed

Lines changed: 58 additions & 30 deletions

File tree

pkg/devspace/helm/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ func createNewClient(kubectlClient *kubernetes.Clientset, log log.Logger, upgrad
132132
os.MkdirAll(repoPath, os.ModePerm)
133133
os.MkdirAll(filepath.Dir(stableRepoCachePathAbs), os.ModePerm)
134134

135-
_, repoFileNotFound := os.Stat(repoFile)
136-
if repoFileNotFound != nil {
135+
repoFileStat, repoFileNotFound := os.Stat(repoFile)
136+
if repoFileNotFound != nil || repoFileStat.Size() == 0 {
137137
err = fsutil.WriteToFile([]byte(defaultRepositories), repoFile)
138138
if err != nil {
139139
return nil, err

pkg/devspace/kubectl/client.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7+
"github.com/covexo/devspace/pkg/util/terminal"
78
"io"
89
"net/http"
910
"os"
@@ -16,7 +17,6 @@ import (
1617
"github.com/covexo/devspace/pkg/devspace/config/configutil"
1718
"github.com/covexo/devspace/pkg/devspace/config/v1"
1819
"github.com/covexo/devspace/pkg/util/log"
19-
dockerterm "github.com/docker/docker/pkg/term"
2020
k8sv1 "k8s.io/api/core/v1"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
"k8s.io/client-go/kubernetes"
@@ -413,7 +413,7 @@ func Exec(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, container string,
413413
SubResource("exec")
414414

415415
if tty {
416-
t = setupTTY()
416+
t = terminal.SetupTTY()
417417
}
418418

419419
execRequest.VersionedParams(&k8sapi.PodExecOptions{
@@ -475,30 +475,6 @@ func Exec(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, container string,
475475
return stdinWriter, stdoutReader, stderrReader, nil
476476
}
477477

478-
func setupTTY() term.TTY {
479-
t := term.TTY{
480-
Out: os.Stdout,
481-
In: os.Stdin,
482-
}
483-
484-
if !t.IsTerminalIn() {
485-
log.Info("Unable to use a TTY - input is not a terminal or the right kind of file")
486-
487-
return t
488-
}
489-
490-
// if we get to here, the user wants to attach stdin, wants a TTY, and In is a terminal, so we
491-
// can safely set t.Raw to true
492-
t.Raw = true
493-
494-
stdin, stdout, _ := dockerterm.StdStreams()
495-
496-
t.In = stdin
497-
t.Out = stdout
498-
499-
return t
500-
}
501-
502478
//ExecBuffered executes a command for kubernetes and returns the output and error buffers
503479
func ExecBuffered(kubectlClient *kubernetes.Clientset, pod *k8sv1.Pod, container string, command []string) ([]byte, []byte, error) {
504480
_, stdout, stderr, execErr := Exec(kubectlClient, pod, container, command, false, nil)

pkg/util/log/loading_text.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import (
55
"io"
66
"time"
77

8+
"github.com/covexo/devspace/pkg/util/terminal"
9+
810
"github.com/daviddengcn/go-colortext"
911
)
1012

1113
const waitInterval = time.Millisecond * 150
1214

15+
var tty = terminal.SetupTTY()
16+
1317
type loadingText struct {
1418
Stream io.Writer
1519
Message string
@@ -71,13 +75,30 @@ func (l *loadingText) render() {
7175
} else {
7276
l.Stream.Write([]byte("\r"))
7377
}
78+
messagePrefix := []byte("[WAIT] ")
7479

7580
ct.Foreground(ct.Red, false)
76-
l.Stream.Write([]byte("[WAIT] "))
81+
l.Stream.Write(messagePrefix)
7782
ct.ResetColor()
7883

7984
timeElapsed := fmt.Sprintf("%d", (time.Now().UnixNano()-l.startTimestamp)/int64(time.Second))
80-
l.Stream.Write([]byte(l.getLoadingChar() + " " + l.Message + " (" + timeElapsed + "s)"))
85+
message := []byte(l.getLoadingChar() + " " + l.Message)
86+
messageSuffix := " (" + timeElapsed + "s)"
87+
terminalSize := tty.GetSize()
88+
prefixLength := len(messagePrefix)
89+
suffixLength := len(messageSuffix)
90+
91+
if uint16(prefixLength+len(message)+suffixLength) > terminalSize.Width {
92+
dots := []byte("...")
93+
maxMessageLength := terminalSize.Width - uint16(prefixLength+suffixLength+len(dots))
94+
95+
if maxMessageLength > 0 {
96+
message = append(message[:maxMessageLength], dots...)
97+
}
98+
}
99+
message = append(message, messageSuffix...)
100+
101+
l.Stream.Write(message)
81102
}
82103

83104
func (l *loadingText) Stop() {

pkg/util/terminal/tty.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package terminal
2+
3+
import (
4+
"os"
5+
6+
dockerterm "github.com/docker/docker/pkg/term"
7+
"k8s.io/kubernetes/pkg/kubectl/util/term"
8+
)
9+
10+
// SetupTTY creates a term.TTY (docker)
11+
func SetupTTY() term.TTY {
12+
t := term.TTY{
13+
Out: os.Stdout,
14+
In: os.Stdin,
15+
}
16+
17+
if !t.IsTerminalIn() {
18+
return t
19+
}
20+
21+
// if we get to here, the user wants to attach stdin, wants a TTY, and In is a terminal, so we
22+
// can safely set t.Raw to true
23+
t.Raw = true
24+
25+
stdin, stdout, _ := dockerterm.StdStreams()
26+
27+
t.In = stdin
28+
t.Out = stdout
29+
30+
return t
31+
}

0 commit comments

Comments
 (0)