Create status support
This commit is contained in:
parent
e57b390d4a
commit
76aca39f5b
6 changed files with 41 additions and 20 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -57,9 +57,11 @@ func ChooseCodespace(ctx context.Context, apiClient *api.API, user *api.User) (*
|
|||
return codespace, nil
|
||||
}
|
||||
|
||||
func ConnectToLiveshare(ctx context.Context, apiClient *api.API, token string, codespace *api.Codespace) (client *liveshare.Client, err error) {
|
||||
func ConnectToLiveshare(ctx context.Context, apiClient *api.API, userLogin, token string, codespace *api.Codespace) (client *liveshare.Client, err error) {
|
||||
var startedCodespace bool
|
||||
if codespace.Environment.State != api.CodespaceEnvironmentStateAvailable {
|
||||
fmt.Println("Starting your codespace...") // TODO(josebalius): better way of notifying of events
|
||||
startedCodespace = true
|
||||
fmt.Print("Starting your codespace...") // TODO(josebalius): better way of notifying of events
|
||||
if err := apiClient.StartCodespace(ctx, token, codespace); err != nil {
|
||||
return nil, fmt.Errorf("error starting codespace: %v", err)
|
||||
}
|
||||
|
|
@ -79,7 +81,7 @@ func ConnectToLiveshare(ctx context.Context, apiClient *api.API, token string, c
|
|||
return nil, errors.New("timed out while waiting for the codespace to start")
|
||||
}
|
||||
|
||||
codespace, err = apiClient.GetCodespace(ctx, token, codespace.OwnerLogin, codespace.Name)
|
||||
codespace, err = apiClient.GetCodespace(ctx, token, userLogin, codespace.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting codespace: %v", err)
|
||||
}
|
||||
|
|
@ -87,10 +89,9 @@ func ConnectToLiveshare(ctx context.Context, apiClient *api.API, token string, c
|
|||
retries += 1
|
||||
}
|
||||
|
||||
if retries >= 2 {
|
||||
if startedCodespace {
|
||||
fmt.Print("\n")
|
||||
}
|
||||
|
||||
fmt.Println("Connecting to your codespace...")
|
||||
|
||||
lsclient, err := liveshare.NewClient(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ type PostCreateStatesResult struct {
|
|||
Err error
|
||||
}
|
||||
|
||||
type PostCreateStates []*PostCreateState
|
||||
type PostCreateStates []PostCreateState
|
||||
|
||||
type PostCreateState struct {
|
||||
Name string `json:"name"`
|
||||
|
|
@ -38,7 +38,7 @@ func PollPostCreateStates(ctx context.Context, apiClient *api.API, user *api.Use
|
|||
return nil, fmt.Errorf("getting codespace token: %v", err)
|
||||
}
|
||||
|
||||
lsclient, err := ConnectToLiveshare(ctx, apiClient, token, codespace)
|
||||
lsclient, err := ConnectToLiveshare(ctx, apiClient, user.Login, token, codespace)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("connect to liveshare: %v", err)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue