mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(cli): show ready sync start dependencies (#25546)
## Problem Follow-on to: - https://github.com/coder/coder/pull/25089 `coder exp sync start` still printed a generic success message when the unit was ready on the first status check. That hid whether the unit had no dependencies or had dependencies that were already satisfied before `sync start` ran. Before: ```text Success ``` ## Solution Print explicit startup output for both ready-at-first-check cases. After, dependencies already satisfied: ```text Unit "test-unit" started immediately, dependencies already satisfied: [dep-unit, dep-unit-2] ``` After, no dependencies: ```text Unit "test-unit" started with no dependencies ``` The existing waiting path is unchanged and still reports the dependencies while waiting and after waiting finishes. Co-authored-by: Sas Swart <sas.swart.cdk@gmail.com>
This commit is contained in:
+19
-12
@@ -57,15 +57,19 @@ func (*RootCmd) syncStart(socketPath *string) *serpent.Command {
|
||||
}
|
||||
ready := statusResp.IsReady
|
||||
|
||||
var waitedFor []string
|
||||
if !ready {
|
||||
for _, dep := range statusResp.Dependencies {
|
||||
if !dep.IsSatisfied {
|
||||
waitedFor = append(waitedFor, string(dep.DependsOn))
|
||||
}
|
||||
var allDependencies []string
|
||||
var unsatisfiedDependencies []string
|
||||
for _, dep := range statusResp.Dependencies {
|
||||
allDependencies = append(allDependencies, string(dep.DependsOn))
|
||||
if !dep.IsSatisfied {
|
||||
unsatisfiedDependencies = append(unsatisfiedDependencies, string(dep.DependsOn))
|
||||
}
|
||||
slices.Sort(waitedFor)
|
||||
waitedForList := strings.Join(waitedFor, ", ")
|
||||
}
|
||||
slices.Sort(allDependencies)
|
||||
slices.Sort(unsatisfiedDependencies)
|
||||
|
||||
if !ready {
|
||||
waitedForList := strings.Join(unsatisfiedDependencies, ", ")
|
||||
|
||||
cliui.Infof(i.Stdout, "Unit %q is waiting for dependencies to be satisfied: [%s]", unitName, waitedForList)
|
||||
|
||||
@@ -96,10 +100,13 @@ func (*RootCmd) syncStart(socketPath *string) *serpent.Command {
|
||||
return xerrors.Errorf("start unit failed: %w", err)
|
||||
}
|
||||
|
||||
if len(waitedFor) == 0 {
|
||||
cliui.Info(i.Stdout, "Success")
|
||||
} else {
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q finished waiting for dependencies: [%s]", unitName, strings.Join(waitedFor, ", ")))
|
||||
switch {
|
||||
case len(allDependencies) == 0:
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q started with no dependencies", unitName))
|
||||
case len(unsatisfiedDependencies) == 0:
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q started immediately, dependencies already satisfied: [%s]", unitName, strings.Join(allDependencies, ", ")))
|
||||
default:
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q finished waiting for dependencies: [%s]", unitName, strings.Join(unsatisfiedDependencies, ", ")))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user