simplify the state iteration
This commit is contained in:
parent
55f0dad3db
commit
46ee45bcdd
3 changed files with 33 additions and 36 deletions
|
|
@ -92,46 +92,42 @@ func Create() error {
|
|||
var lastState codespaces.PostCreateState
|
||||
var breakNextState bool
|
||||
|
||||
PollStates:
|
||||
for {
|
||||
select {
|
||||
case stateUpdate := <-states:
|
||||
if stateUpdate.Err != nil {
|
||||
return fmt.Errorf("receive state update: %v", err)
|
||||
}
|
||||
stateUpdate := <-states
|
||||
if stateUpdate.Err != nil {
|
||||
return fmt.Errorf("receive state update: %v", err)
|
||||
}
|
||||
|
||||
var inProgress bool
|
||||
for _, state := range stateUpdate.PostCreateStates {
|
||||
switch state.Status {
|
||||
case codespaces.PostCreateStateRunning:
|
||||
if lastState != state {
|
||||
lastState = state
|
||||
fmt.Print(state.Name)
|
||||
} else {
|
||||
fmt.Print(".")
|
||||
}
|
||||
var inProgress bool
|
||||
for _, state := range stateUpdate.PostCreateStates {
|
||||
switch state.Status {
|
||||
case codespaces.PostCreateStateRunning:
|
||||
if lastState != state {
|
||||
lastState = state
|
||||
log.Print(state.Name)
|
||||
} else {
|
||||
log.Print(".")
|
||||
}
|
||||
|
||||
inProgress = true
|
||||
break
|
||||
case codespaces.PostCreateStateFailed:
|
||||
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")
|
||||
}
|
||||
inProgress = true
|
||||
break
|
||||
case codespaces.PostCreateStateFailed:
|
||||
if lastState.Name == state.Name && lastState.Status != state.Status {
|
||||
lastState = state
|
||||
log.Print(".Failed\n")
|
||||
}
|
||||
case codespaces.PostCreateStateSuccess:
|
||||
if lastState.Name == state.Name && lastState.Status != state.Status {
|
||||
lastState = state
|
||||
log.Print(".Success\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case !inProgress && !breakNextState:
|
||||
breakNextState = true
|
||||
case !inProgress && breakNextState:
|
||||
break PollStates
|
||||
}
|
||||
if !inProgress && !breakNextState {
|
||||
breakNextState = true
|
||||
} else if !inProgress && breakNextState {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
|||
return fmt.Errorf("error creating liveshare terminal: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Preparing SSH...")
|
||||
log.Print("Preparing SSH...")
|
||||
if sshProfile == "" {
|
||||
containerID, err := getContainerID(ctx, log, terminal)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func ConnectToLiveshare(ctx context.Context, log logger, apiClient *api.API, use
|
|||
var startedCodespace bool
|
||||
if codespace.Environment.State != api.CodespaceEnvironmentStateAvailable {
|
||||
startedCodespace = true
|
||||
log.Println("Starting your codespace...")
|
||||
log.Print("Starting your codespace...")
|
||||
if err := apiClient.StartCodespace(ctx, token, codespace); err != nil {
|
||||
return nil, fmt.Errorf("error starting codespace: %v", err)
|
||||
}
|
||||
|
|
@ -97,6 +97,7 @@ func ConnectToLiveshare(ctx context.Context, log logger, apiClient *api.API, use
|
|||
if startedCodespace {
|
||||
fmt.Print("\n")
|
||||
}
|
||||
|
||||
log.Println("Connecting to your codespace...")
|
||||
|
||||
lsclient, err := liveshare.NewClient(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue