Create status support

This commit is contained in:
Jose Garcia 2021-08-04 17:35:11 +00:00 committed by GitHub
parent e57b390d4a
commit 76aca39f5b
6 changed files with 41 additions and 20 deletions

View file

@ -86,6 +86,10 @@ func Create() error {
return fmt.Errorf("poll post create states: %v", err)
}
var lastState codespaces.PostCreateState
var breakNextState bool
PollStates:
for {
select {
case stateUpdate := <-states:
@ -95,18 +99,35 @@ func Create() error {
var inProgress bool
for _, state := range stateUpdate.PostCreateStates {
fmt.Print(state.Name)
switch state.Status {
case codespaces.PostCreateStateRunning:
if lastState != state {
lastState = state
fmt.Print(state.Name)
} else {
fmt.Print(".")
}
inProgress = true
break
case codespaces.PostCreateStateFailed:
fmt.Print("...Failed")
if lastState.Name == state.Name && lastState.Status != state.Status {
lastState = state
fmt.Print(".Failed\n")
}
case codespaces.PostCreateStateSuccess:
if lastState.Name == state.Name && lastState.Status != state.Status {
lastState = state
fmt.Print(".Success\n")
}
}
fmt.Print("\n")
}
if !inProgress {
break
switch {
case !inProgress && !breakNextState:
breakNextState = true
case !inProgress && breakNextState:
break PollStates
}
}
}

View file

@ -49,7 +49,7 @@ func Logs(tail bool, codespaceName string) error {
return fmt.Errorf("get or choose codespace: %v", err)
}
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, user.Login, token, codespace)
if err != nil {
return fmt.Errorf("connecting to liveshare: %v", err)
}

View file

@ -61,7 +61,7 @@ func Ports() error {
return fmt.Errorf("error getting codespace token: %v", err)
}
liveShareClient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
liveShareClient, err := codespaces.ConnectToLiveshare(ctx, apiClient, user.Login, token, codespace)
if err != nil {
return fmt.Errorf("error connecting to liveshare: %v", err)
}
@ -214,7 +214,7 @@ func updatePortVisibility(codespaceName, sourcePort string, public bool) error {
return fmt.Errorf("error getting codespace: %v", err)
}
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, user.Login, token, codespace)
if err != nil {
return fmt.Errorf("error connecting to liveshare: %v", err)
}
@ -276,7 +276,7 @@ func forwardPort(codespaceName, sourcePort, destPort string) error {
return fmt.Errorf("error getting codespace: %v", err)
}
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, user.Login, token, codespace)
if err != nil {
return fmt.Errorf("error connecting to liveshare: %v", err)
}

View file

@ -51,7 +51,7 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
return fmt.Errorf("get or choose codespace: %v", err)
}
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, token, codespace)
lsclient, err := codespaces.ConnectToLiveshare(ctx, apiClient, user.Login, token, codespace)
if err != nil {
return fmt.Errorf("error connecting to liveshare: %v", err)
}
@ -61,7 +61,7 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
return fmt.Errorf("error creating liveshare terminal: %v", err)
}
fmt.Println("Preparing SSH...")
fmt.Print("Preparing SSH...")
if sshProfile == "" {
containerID, err := getContainerID(ctx, terminal)
if err != nil {
@ -71,9 +71,8 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
if err := setupSSH(ctx, terminal, containerID, codespace.RepositoryName); err != nil {
return fmt.Errorf("error creating ssh server: %v", err)
}
fmt.Printf("\n")
}
fmt.Print("\n")
tunnelPort, tunnelClosed, err := codespaces.MakeSSHTunnel(ctx, lsclient, sshServerPort)
if err != nil {